Skip to content

Commit

Permalink
fix: test empty entities array
Browse files Browse the repository at this point in the history
  • Loading branch information
tflori committed Sep 13, 2019
1 parent af774e1 commit 9783e10
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ php:
- 5.6
- 7.1
- 7.2
- 7.3

sudo: false

Expand All @@ -23,4 +24,6 @@ before_script:
script:
- composer code-style
- vendor/bin/phpunit -c phpunit.xml --coverage-clover=build/logs/clover.xml --coverage-text --color=always
- sh -c 'if [ "$TRAVIS_PHP_VERSION" = "7.0" ]; then php vendor/bin/coveralls -v; fi;'

after_success:
- sh -c 'if [ "$TRAVIS_PHP_VERSION" = "7.1" ]; then php vendor/bin/coveralls -v; fi;'
4 changes: 3 additions & 1 deletion src/Testing/EntityFetcherMock/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ public function matches($expression)
*/
public function addEntities(Entity ...$entities)
{
array_push($this->entities, ...$entities);
if (!empty($entities)) {
array_push($this->entities, ...$entities);
}
return $this;
}

Expand Down
13 changes: 13 additions & 0 deletions tests/Testing/EntityFetcherMockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ public function returnsAnEmptyArrayIfNoResultsMatch()
self::assertEmpty($articles);
}

/** @test */
public function returnsAnEmptyResultIfMatched()
{
$this->em->addResult(Article::class, new Article(['title' => 'Foo']));
$this->em->addResult(Article::class)->where('title', 'Bar');

$query = new EntityFetcherMock($this->em, Article::class);
$query->where('title', 'Bar');
$articles = $query->all();

self::assertEmpty($articles);
}

/** @test */
public function returnsEntitiesWithoutConditions()
{
Expand Down

0 comments on commit 9783e10

Please sign in to comment.