Comments (4)
the decoration feature is currently under development. I've implemented it, it is under review and we are planning to release it in Pest V2: it will be renamed to expectation()->pipe()
and will also include expectation()->intercept()
for completely replacing the original expectation (that is, I think, what you need most of times)
I've already opened some issues here as reminders for implementing expect($mode)->toBe($anotherModel)
(and also for Carbon, etc.). These needs gave me the idea for that feature
toHave
is an interesting one, I'll take a look a it!
from pest-plugin-laravel-expectations.
Damn, that was a typo that went unnoticed 🤦
sorry, I've released 1.6.0 that was the intended version, hope that this will fix your issue
Hi I keep some pretty massive pest setups which I keep meaning to delegate to a package and it's even better that you are doing it for me! So first off, thanks!
I'm happy to help! let me know if there are more expectation that you would find useful in this package!
from pest-plugin-laravel-expectations.
Bud! that was fast thanks!
I'm happy to help! let me know if there are more expectation that you would find useful in this package!
You've covered a lot of ground here, what I'm really waiting for is that decorator I think I saw in the discord! I thought I saw a tweet about it a while back. Decorators will let me push clearer tests using better words that may have already been used to test another type. I often wonder why more people aren't talking about this it makes me wonder if there is a better way that I'm just missing.
but expect($aCollection)->toContain($anItem) is my first candidate for a decorator. I think you have assertJSonSubset covered with the jsonFragment, but I haven't swapped it out yet.
I'd love to decorate of course expect($mode)->toBe($anotherModel) rather than writing isSameModel or toBeTheSameAs.
I've played around with carbon functions, but you've blown that all away. I've been using this as a bit of a catch all for toContain . It's not formatted for a package but does sit nicely in a few Pest files, and it's growing on me.
expect()->extend('toHave', function (Model|int|string|array $item) {
$iterable = $this->value;
if ( $iterable instanceof Illuminate\Database\Eloquent\Collection ||
( $iterable instanceof Collection &&
is_subclass_of($iterable->first(), Model::class) )
) {
if ( is_scalar($item) ) {
$id = $item;
} else {
$id = $item->getKey();
}
// each item is an eloquent model
$key = $iterable->first()->getKeyName();
return $this->keyBy($key)->toHaveKey($id);
}
if ( is_array($item) ) {
throw new Exception("If you are looking for each key individually, try modifying the test to " .
"->toHave(" . collect($item)->values()->join(', ') . "); Otherwise use"
. "\ntoHaveProperty(), toHaveProperties(), or toMatchArray() when searching for an array\n\n->toHave(" . print_r($item, true) . ");\n\nhttps://pestphp.com/docs/expectations#expect-toHaveProperty\n");
}
return $this->toContain($item);
});
expect()->extend('doesntHave', function (Model|int $item) {
return $this->not()->toHave($item);
});
I don't mind how it reads
test('a user can follow another user', function () {
$user = User::Factory()->create();
$user2 = User::Factory()->create();
$follower = User::Factory()->create();
$follower->follow($user);
expect($follower->follows)
->toBeInstanceOf(Collection::class)
->toHaveCount(1)
->toHave($user)
->not->toHave($user2);
});
//Or
expect($user->permissions)->toHave($permission1, $permission2);
from pest-plugin-laravel-expectations.
Closing this issue you've resolved this already :)
from pest-plugin-laravel-expectations.
Related Issues (20)
- example code shoud contain toBeRedirectToSignedRoute() instead toBeRedirect HOT 5
- expect($carbon)->toBeTomorrow()
- expect($carbon)->toBeNextWeek()
- expect($carbon)->toBeLastWeek()
- expect($carbon)->toBeCurrentHour()
- expect($carbon)->toBeSameMinuteAs($anotherCarbon)
- expect($carbon)->toBeCurrentMinute()
- expect($carbon)->toBeCurrentSecond()
- expect($carbon)->toBeSameSecondAs($anotherCarbon)
- expect($carbon)->toBeStartOfDay()
- expect($carbon)->toBeMidnight()
- expect($carbon)->toBeEndOfDay()
- expect($carbon)->toBeMidday()
- expect($carbon)->toBeBirthday()
- expect($model)->toBe($anotherModel)
- expect($carbon)->toBe($anotherCarbon)
- expect($model)->toBeSameModelAs($anotherModel)
- Expect output to contain
- Expect, get/set
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pest-plugin-laravel-expectations.