|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Acme\Filter; |
| 4 | + |
| 5 | +use olvlvl\ComposerAttributeCollector\Filter\ClassFilter; |
| 6 | +use olvlvl\ComposerAttributeCollector\Logger; |
| 7 | +use PHPUnit\Framework\TestCase; |
| 8 | +use tests\olvlvl\ComposerAttributeCollector\FakeLogger; |
| 9 | + |
| 10 | +final class ClassFilterTest extends TestCase |
| 11 | +{ |
| 12 | + private string $path; |
| 13 | + private ClassFilter $sut; |
| 14 | + private FakeLogger $log; |
| 15 | + |
| 16 | + protected function setUp(): void |
| 17 | + { |
| 18 | + // The path doesn't matter. |
| 19 | + $this->path = uniqid(); |
| 20 | + $this->sut = new ClassFilter(); |
| 21 | + $this->log = new FakeLogger(); |
| 22 | + |
| 23 | + parent::setUp(); |
| 24 | + } |
| 25 | + |
| 26 | + public function testWithClass(): void |
| 27 | + { |
| 28 | + $actual = $this->sut->filter($this->path, \Acme\PSR4\CreateMenuHandler::class, $this->log); |
| 29 | + |
| 30 | + $this->assertTrue($actual); |
| 31 | + } |
| 32 | + |
| 33 | + public function testWithInterface(): void |
| 34 | + { |
| 35 | + $actual = $this->sut->filter($this->path, \Acme\PSR4\SignatureMapProvider::class, $this->log); |
| 36 | + |
| 37 | + $this->assertTrue($actual); |
| 38 | + } |
| 39 | + |
| 40 | + public function testWithTrait(): void |
| 41 | + { |
| 42 | + $actual = $this->sut->filter($this->path, \Acme\PSR4\SampleTrait::class, $this->log); |
| 43 | + |
| 44 | + $this->assertTrue($actual); |
| 45 | + } |
| 46 | + |
| 47 | + public function testDiscardOnError(): void |
| 48 | + { |
| 49 | + $log = $this->createMock(Logger::class); |
| 50 | + $log->expects($this->once()) |
| 51 | + ->method('warning') |
| 52 | + ->with($this->stringStartsWith("Discarding 'Acme\PSR4\MissingInterface")); |
| 53 | + |
| 54 | + $actual = $this->sut->filter($this->path, \Acme\PSR4\MissingInterface::class, $log); |
| 55 | + |
| 56 | + $this->assertFalse($actual); |
| 57 | + } |
| 58 | +} |
0 commit comments