Skip to content

Commit

Permalink
Merge branch 'master' into 9.x
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-ivanov committed Aug 21, 2022
2 parents c0b3e41 + 3a25ad3 commit 7b91ebf
Show file tree
Hide file tree
Showing 17 changed files with 6 additions and 786 deletions.
196 changes: 0 additions & 196 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ Laravel-specific Testing Helpers and Assertions.
- [emulateLocal](#emulatelocal)
- [emulateProduction](#emulateproduction)
- [emulateEnvironment](#emulateenvironment)
- [isTravis](#istravis)

## Available assertions

Expand All @@ -88,21 +87,6 @@ Laravel-specific Testing Helpers and Assertions.
- [assertDatabaseMissingTable](#assertdatabasemissingtable)
- [assertDatabaseHasMany](#assertdatabasehasmany)
- [assertDatabaseMissingMany](#assertdatabasemissingmany)
- [EloquentAsserts](#eloquentasserts)
- [assertEloquentTableEquals](#asserteloquenttableequals)
- [assertEloquentTableNotEquals](#asserteloquenttablenotequals)
- [assertEloquentIsIncrementing](#asserteloquentisincrementing)
- [assertEloquentIsNotIncrementing](#asserteloquentisnotincrementing)
- [assertEloquentFillableEquals](#asserteloquentfillableequals)
- [assertEloquentFillableNotEquals](#asserteloquentfillablenotequals)
- [assertEloquentDatesEquals](#asserteloquentdatesequals)
- [assertEloquentDatesNotEquals](#asserteloquentdatesnotequals)
- [assertEloquentTouchesEquals](#asserteloquenttouchesequals)
- [assertEloquentTouchesNotEquals](#asserteloquenttouchesnotequals)
- [assertEloquentHasMany](#asserteloquenthasmany)
- [assertEloquentHasCreateFor](#asserteloquenthascreatefor)
- [assertEloquentHasCreateManyFor](#asserteloquenthascreatemanyfor)
- [assertEloquentBelongsTo](#asserteloquentbelongsto)
- [ExceptionAsserts](#exceptionasserts)
- [willSeeException](#willseeexception)
- [FilesystemAsserts](#filesystemasserts)
Expand Down Expand Up @@ -161,16 +145,6 @@ Emulate that application is running on the given environment:
$this->emulateEnvironment('demo');
```

#### `isTravis()`

Check whether the application is running on Travis or not:

```php
$this->isTravis();
// true
```

## Assertions

### CollectionAsserts
Expand Down Expand Up @@ -232,176 +206,6 @@ $this->assertDatabaseMissingMany('posts', [
]);
```

### EloquentAsserts

#### `assertEloquentTableEquals()`

Assert that the model's table name equals to the given value:
```php
$this->assertEloquentTableEquals(User::class, 'users');
```
#### `assertEloquentTableNotEquals()`
Assert that the model's table name doesn't equal to the given value:
```php
$this->assertEloquentTableNotEquals(User::class, 'posts');
```
#### `assertEloquentIsIncrementing()`
Assert that the model's primary key is incrementing:

```php
$this->assertEloquentIsIncrementing(Post::class);
```

#### `assertEloquentIsNotIncrementing()`

Assert that the model's primary key is not incrementing:
```php
$this->assertEloquentIsNotIncrementing(Category::class);
```
#### `assertEloquentFillableEquals()`
Assert that the model's `fillable` field equals to the given value:

```php
$this->assertEloquentFillableEquals(Post::class, ['title', 'publish_at']);
```

#### `assertEloquentFillableNotEquals()`

Assert that the model's `fillable` field doesn't equal to the given value:

```php
$this->assertEloquentFillableNotEquals(Post::class, ['title', 'body', 'publish_at']);
```

#### `assertEloquentDatesEquals()`

Assert that the model's `dates` field equals to the given value:
```php
$this->assertEloquentDatesEquals(Post::class, ['publish_at', 'created_at', 'updated_at']);
```
#### `assertEloquentDatesNotEquals()`
Assert that the model's `dates` field doesn't equal to the given value:
```php
$this->assertEloquentDatesNotEquals(Post::class, ['publish_at']);
```
#### `assertEloquentTouchesEquals()`
Assert that the model's `touches` field equals to the given value:

```php
$this->assertEloquentTouchesEquals(Comment::class, ['post']);
```

#### `assertEloquentTouchesNotEquals()`

Assert that the model's `touches` field doesn't equal to the given value:

```php
$this->assertEloquentTouchesNotEquals(Comment::class, ['user']);
```

#### `assertEloquentHasMany()`

> NOTE: To use this assertion, you have to create model factories for both classes.

Assert that the model has the given `HasMany` relation:

```php
$this->assertEloquentHasMany(Post::class, 'comments');
```

Assuming that `Post` class has `comments` relation:

```php
class Post extends Model
{
public function comments()
{
return $this->hasMany(Comment::class);
}
}
```

#### `assertEloquentHasCreateFor()`

> NOTE: To use this assertion, you have to create model factories for both classes.

Assert that the model has `create` method for the given `HasMany` relation:

```php
$this->assertEloquentHasCreateFor(Post::class, 'comments');
```

Assuming that `Post` class has `createComment()` method:
```php
class Post extends Model
{
public function createComment(array $attributes)
{
return $this->comments()->create($attributes);
}
}
```
#### `assertEloquentHasCreateManyFor()`
> NOTE: To use this assertion, you have to create model factories for both classes.
Assert that the model has `createMany` method for the given `HasMany` relation:
```php
$this->assertEloquentHasCreateManyFor(Post::class, 'comments');
```
Assuming that `Post` class has `createManyComments()` method:
```php
class Post extends Model
{
public function createManyComments(array $comments)
{
return $this->comments()->createMany($comments);
}
}
```
#### `assertEloquentBelongsTo()`
> NOTE: To use this assertion, you have to create model factories for both classes.
Assert that the model has the given `BelongsTo` relation:
```php
$this->assertEloquentBelongsTo(Comment::class, 'post');
```
Assuming that `Comment` class has `post` relation:
```php
class Comment extends Model
{
public function post()
{
return $this->belongsTo(Post::class);
}
}
```
### ExceptionAsserts

#### `willSeeException()`
Expand Down
12 changes: 6 additions & 6 deletions src/Asserts/CollectionAsserts.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ trait CollectionAsserts
*/
protected function assertCollectionsEqual(Collection $collection1, Collection $collection2, string $key): void
{
$this->assertEquals(
$collection1->pluck($key)->sort()->values(),
$collection2->pluck($key)->sort()->values(),
$this->assertEqualsCanonicalizing(
$collection1->pluck($key),
$collection2->pluck($key),
'Failed asserting that collections are equal.',
);
}
Expand All @@ -23,9 +23,9 @@ protected function assertCollectionsEqual(Collection $collection1, Collection $c
*/
protected function assertCollectionsNotEqual(Collection $collection1, Collection $collection2, string $key): void
{
$this->assertNotEquals(
$collection1->pluck($key)->sort()->values(),
$collection2->pluck($key)->sort()->values(),
$this->assertNotEqualsCanonicalizing(
$collection1->pluck($key),
$collection2->pluck($key),
'Failed asserting that collections are not equal.',
);
}
Expand Down
Loading

0 comments on commit 7b91ebf

Please sign in to comment.