.
This commit is contained in:
commit
a5ce423afe
30 changed files with 1807 additions and 0 deletions
67
tests/AspectStackingTest.php
Normal file
67
tests/AspectStackingTest.php
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Tests\Classes\StackedAspectsClass;
|
||||
use Tests\Aspects\LoggingAspect;
|
||||
|
||||
final class AspectStackingTest extends TestCase
|
||||
{
|
||||
private StackedAspectsClass $instance;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->instance = new StackedAspectsClass();
|
||||
LoggingAspect::clearLogs();
|
||||
}
|
||||
|
||||
public function testMultipleAspectsExecuteInOrder(): void
|
||||
{
|
||||
$tracker = (object) ['before' => false, 'after' => false];
|
||||
$result = $this->instance->multipleAspects(10, $tracker);
|
||||
|
||||
$this->assertEquals(20, $result);
|
||||
$this->assertTrue($tracker->before);
|
||||
$this->assertTrue($tracker->after);
|
||||
|
||||
$this->assertCount(2, LoggingAspect::$logs);
|
||||
$this->assertEquals('logging_before', LoggingAspect::$logs[0]['type']);
|
||||
$this->assertEquals('logging_after', LoggingAspect::$logs[1]['type']);
|
||||
$this->assertEquals(20, LoggingAspect::$logs[1]['result']);
|
||||
}
|
||||
|
||||
public function testSingleBasicAspect(): void
|
||||
{
|
||||
$tracker = (object) ['before' => false, 'after' => false];
|
||||
$result = $this->instance->onlyBasic(5, $tracker);
|
||||
|
||||
$this->assertEquals(6, $result);
|
||||
$this->assertTrue($tracker->before);
|
||||
$this->assertTrue($tracker->after);
|
||||
$this->assertEmpty(LoggingAspect::$logs);
|
||||
}
|
||||
|
||||
public function testSingleLoggingAspect(): void
|
||||
{
|
||||
$result = $this->instance->onlyLogging('hello');
|
||||
|
||||
$this->assertEquals('HELLO', $result);
|
||||
$this->assertCount(2, LoggingAspect::$logs);
|
||||
$this->assertEquals('logging_before', LoggingAspect::$logs[0]['type']);
|
||||
$this->assertEquals('logging_after', LoggingAspect::$logs[1]['type']);
|
||||
}
|
||||
|
||||
public function testNoAspects(): void
|
||||
{
|
||||
$result = $this->instance->noAspects();
|
||||
$this->assertEquals('plain', $result);
|
||||
$this->assertEmpty(LoggingAspect::$logs);
|
||||
}
|
||||
|
||||
public function testAspectsReceiveCorrectArguments(): void
|
||||
{
|
||||
$tracker = (object) ['before' => false, 'after' => false];
|
||||
$this->instance->multipleAspects(15, $tracker);
|
||||
|
||||
$this->assertEquals([15, $tracker], LoggingAspect::$logs[0]['args']);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue