|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Tests\Unit\WpOrg\UrlParser; |
| 6 | + |
| 7 | +use Composer\Cache as ComposerCache; |
| 8 | +use Mockery; |
| 9 | +use TypistTech\WpOrgClosedPlugin\WpOrg\Api\Cache; |
| 10 | + |
| 11 | +covers(Cache::class); |
| 12 | + |
| 13 | +describe(Cache::class, static function (): void { |
| 14 | + dataset('slugs', static function (): array { |
| 15 | + return [ |
| 16 | + // Closed. |
| 17 | + 'unused_permanent' => ['spam-stopgap', true, 'closed'], |
| 18 | + // Not closed. |
| 19 | + 'open' => ['hello-dolly', false, 'open'], |
| 20 | + ]; |
| 21 | + }); |
| 22 | + |
| 23 | + describe('::read()', static function (): void { |
| 24 | + it('reads the first line', function (): void {}); |
| 25 | + |
| 26 | + test('when missed', function (): void {}); |
| 27 | + |
| 28 | + test('when expired', function (): void {}); |
| 29 | + |
| 30 | + test('when unexpected content', function (): void {}); |
| 31 | + }); |
| 32 | + |
| 33 | + describe('::write()', static function (): void { |
| 34 | + it('writes the result into {$slug}.txt as the first line', function (string $slug, bool $isClosed, string $expected): void { |
| 35 | + $composerCache = Mockery::spy(ComposerCache::class); |
| 36 | + $cache = new Cache($composerCache); |
| 37 | + |
| 38 | + $cache->write($slug, $isClosed); |
| 39 | + |
| 40 | + $composerCache->shouldHaveReceived('write', [ |
| 41 | + "{$slug}.txt", |
| 42 | + Mockery::on(static fn (string $actual) => str_starts_with($actual, $expected."\n")), |
| 43 | + ]); |
| 44 | + })->with('slugs'); |
| 45 | + |
| 46 | + test('when composer cache is read only', function (string $slug, bool $isClosed): void { |
| 47 | + $composerCache = Mockery::spy(ComposerCache::class); |
| 48 | + $composerCache->allows() |
| 49 | + ->isReadOnly() |
| 50 | + ->andReturnTrue(); |
| 51 | + |
| 52 | + $cache = new Cache($composerCache); |
| 53 | + |
| 54 | + $cache->write($slug, $isClosed); |
| 55 | + |
| 56 | + $composerCache->shouldNotHaveReceived('write'); |
| 57 | + })->with('slugs'); |
| 58 | + }); |
| 59 | +})->only(); |
0 commit comments