Skip to content

Commit

Permalink
Get rid of phpspec/prophecy-phpunit. (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol authored Mar 27, 2022
1 parent 2a0c84d commit 8f8ae04
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 24 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"drupol/php-conventions": "^5",
"infection/infection": "^0.26.0",
"loophp/phpunit-iterable-assertions": "^1.0",
"phpspec/prophecy-phpunit": "^2.0",
"phpstan/phpstan-strict-rules": "^1.0",
"phpunit/php-code-coverage": "^9.2",
"phpunit/phpunit": "^9.5",
Expand Down
9 changes: 5 additions & 4 deletions docs/pages/tests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ run the tests.
Tests are written with `PHPUnit`_ and you can find the coverage percentage
on a badge on the README file.

`PHPInfection`_ is also triggered used to ensure that your code is properly tested.
`PHPInfection`_ is also triggered used to ensure that your code is properly
tested.

The code style is based on `PSR-12`_ plus a set of custom rules.
Find more about the code style in use in the package `drupol/php-conventions`_.

A PHP quality tool, Grumphp_, is used to orchestrate all these tasks at each commit
on the local machine, but also on the continuous integration tools.
A PHP quality tool, Grumphp_, is used to orchestrate all these tasks at each
commit on the local machine, but also on the continuous integration tools.

To run the whole tests tasks locally, do

Expand Down Expand Up @@ -53,6 +54,6 @@ will check your code
.. _PSR-12: https://www.php-fig.org/psr/psr-12/
.. _drupol/php-conventions: https://github.com/drupol/php-conventions
.. _Github Actions: https://github.com/loophp/collection/actions
.. _PHPSpec: https://www.phpunit.de/
.. _PHPUnit: https://www.phpunit.de/
.. _PHPInfection: https://github.com/infection/infection
.. _Grumphp: https://github.com/phpro/grumphp
27 changes: 8 additions & 19 deletions tests/unit/Iterator/PsrCacheIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use ArrayIterator;
use loophp\collection\Iterator\PsrCacheIterator;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\CacheItem;

Expand All @@ -22,38 +21,32 @@
*/
final class PsrCacheIteratorTest extends TestCase
{
use ProphecyTrait;

public function testCacheData(): void
{
$cache = $this->prophesize(CacheItemPoolInterface::class);
$cache = $this->createMock(CacheItemPoolInterface::class);
$it = new ArrayIterator(range('a', 'e'));

$iterator = new PsrCacheIterator($it, $cache->reveal());
$iterator = new PsrCacheIterator($it, $cache);

$cacheItem = new CacheItem();
$cacheItem->set('a');

$cache
->save($cacheItem)
->method('save', $cacheItem)
->willReturn(true);

$cache
->getItem(0)
->method('getItem', 0)
->willReturn($cacheItem);

$cache
->hasItem(0)
->method('hasItem', 0)
->willReturn(true);

$iterator->rewind();

self::assertSame('a', $iterator->current());

$cache
->getItem(0)
->shouldHaveBeenCalledOnce();

$iterator->rewind();

self::assertSame('a', $iterator->current());
Expand All @@ -62,23 +55,19 @@ public function testCacheData(): void
$cacheItem->set('b');

$cache
->save($cacheItem)
->method('save', $cacheItem)
->willReturn(true);

$cache
->getItem(1)
->method('getItem', 1)
->willReturn($cacheItem);

$cache
->hasItem(1)
->method('hasItem', 1)
->willReturn(false);

$iterator->next();

self::assertSame('b', $iterator->current());

$cache
->save($cacheItem)
->shouldHaveBeenCalledOnce();
}
}

0 comments on commit 8f8ae04

Please sign in to comment.