feat: scaffold plugin foundation
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace WPContentSync\Tests\Unit;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use WPContentSync\Container;
|
||||
|
||||
class ContainerTest extends TestCase {
|
||||
public function test_it_returns_registered_service(): void {
|
||||
$container = new Container();
|
||||
$service = new \stdClass();
|
||||
|
||||
$container->set( 'example', $service );
|
||||
|
||||
self::assertSame( $service, $container->get( 'example' ) );
|
||||
}
|
||||
|
||||
public function test_it_reuses_factory_result(): void {
|
||||
$container = new Container();
|
||||
$calls = 0;
|
||||
|
||||
$container->factory(
|
||||
'example',
|
||||
static function () use ( &$calls ): \stdClass {
|
||||
++$calls;
|
||||
return new \stdClass();
|
||||
}
|
||||
);
|
||||
|
||||
$first = $container->get( 'example' );
|
||||
$second = $container->get( 'example' );
|
||||
|
||||
self::assertSame( $first, $second );
|
||||
self::assertSame( 1, $calls );
|
||||
}
|
||||
|
||||
public function test_it_throws_for_unknown_service(): void {
|
||||
$container = new Container();
|
||||
|
||||
$this->expectException( \InvalidArgumentException::class );
|
||||
$this->expectExceptionMessage( 'Service "missing" is not registered.' );
|
||||
|
||||
$container->get( 'missing' );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user