|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace GeekCell\Ddd\Tests\Domain; |
| 6 | + |
| 7 | +use GeekCell\Ddd\Contracts\Domain\Repository; |
| 8 | +use GeekCell\Ddd\Domain\ChainRepository; |
| 9 | +use Mockery; |
| 10 | +use PHPUnit\Framework\TestCase; |
| 11 | + |
| 12 | +/** |
| 13 | + * Test subject. |
| 14 | + * |
| 15 | + * @package GeekCell\Ddd\Tests\Domain |
| 16 | + */ |
| 17 | +class TestChainRepository extends ChainRepository |
| 18 | +{ |
| 19 | + public function select(Repository $repository): void |
| 20 | + { |
| 21 | + $this->selectPrimary($repository); |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +class ChainRepositoryTest extends TestCase |
| 26 | +{ |
| 27 | + public function testChainDefault(): void |
| 28 | + { |
| 29 | + // Given |
| 30 | + $mockFirst = Mockery::mock(Repository::class); |
| 31 | + $mockSecond = Mockery::mock(Repository::class); |
| 32 | + $mockThird = Mockery::mock(Repository::class); |
| 33 | + |
| 34 | + $chainRepository = new TestChainRepository( |
| 35 | + $mockFirst, |
| 36 | + $mockSecond, |
| 37 | + $mockThird, |
| 38 | + ); |
| 39 | + |
| 40 | + /** @var Mockery\MockInterface $mockFirst */ |
| 41 | + $mockFirst->expects('collect')->once(); |
| 42 | + $mockFirst->expects('paginate')->once(); |
| 43 | + $mockFirst->expects('getIterator')->once(); |
| 44 | + $mockFirst->expects('count')->once(); |
| 45 | + |
| 46 | + /** @var Mockery\MockInterface $mockSecond */ |
| 47 | + $mockSecond->expects('collect')->never(); |
| 48 | + $mockSecond->expects('paginate')->never(); |
| 49 | + $mockSecond->expects('getIterator')->never(); |
| 50 | + $mockSecond->expects('count')->never(); |
| 51 | + |
| 52 | + /** @var Mockery\MockInterface $mockThird */ |
| 53 | + $mockThird->expects('collect')->never(); |
| 54 | + $mockThird->expects('paginate')->never(); |
| 55 | + $mockThird->expects('getIterator')->never(); |
| 56 | + $mockThird->expects('count')->never(); |
| 57 | + |
| 58 | + // When |
| 59 | + $chainRepository->collect(); |
| 60 | + $chainRepository->paginate(10); |
| 61 | + $chainRepository->getIterator(); |
| 62 | + $chainRepository->count(); |
| 63 | + |
| 64 | + $this->addToAssertionCount(12); |
| 65 | + } |
| 66 | + |
| 67 | + public function testChainSelect(): void |
| 68 | + { |
| 69 | + // Given |
| 70 | + $mockFirst = Mockery::mock(Repository::class); |
| 71 | + $mockSecond = Mockery::mock(Repository::class); |
| 72 | + $mockThird = Mockery::mock(Repository::class); |
| 73 | + |
| 74 | + $chainRepository = new TestChainRepository( |
| 75 | + $mockFirst, |
| 76 | + $mockSecond, |
| 77 | + $mockThird, |
| 78 | + ); |
| 79 | + |
| 80 | + /** @var Mockery\MockInterface $mockFirst */ |
| 81 | + $mockFirst->expects('collect')->never(); |
| 82 | + $mockFirst->expects('paginate')->never(); |
| 83 | + $mockFirst->expects('getIterator')->never(); |
| 84 | + $mockFirst->expects('count')->never(); |
| 85 | + |
| 86 | + /** @var Mockery\MockInterface $mockSecond */ |
| 87 | + $mockSecond->expects('collect')->once(); |
| 88 | + $mockSecond->expects('paginate')->once(); |
| 89 | + $mockSecond->expects('getIterator')->once(); |
| 90 | + $mockSecond->expects('count')->once(); |
| 91 | + |
| 92 | + /** @var Mockery\MockInterface $mockThird */ |
| 93 | + $mockThird->expects('collect')->never(); |
| 94 | + $mockThird->expects('paginate')->never(); |
| 95 | + $mockThird->expects('getIterator')->never(); |
| 96 | + $mockThird->expects('count')->never(); |
| 97 | + |
| 98 | + // When |
| 99 | + |
| 100 | + /** @var Repository $mockSecond */ |
| 101 | + $chainRepository->select($mockSecond); |
| 102 | + $chainRepository->collect(); |
| 103 | + $chainRepository->paginate(10); |
| 104 | + $chainRepository->getIterator(); |
| 105 | + $chainRepository->count(); |
| 106 | + |
| 107 | + $this->addToAssertionCount(12); |
| 108 | + } |
| 109 | +} |
0 commit comments