Skip to content

Commit

Permalink
Fix: Avoid useless tests for ContainerBuilder (#730)
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz authored Sep 5, 2023
1 parent 8836f79 commit 976c9df
Showing 1 changed file with 44 additions and 20 deletions.
64 changes: 44 additions & 20 deletions test/Faker/Extension/ContainerBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
namespace Faker\Test\Extension;

use Faker\Container\ContainerBuilder;
use Faker\Container\ContainerInterface;
use Faker\Core\File;
use Faker\Core\Number;
use Faker\Extension;
use PHPUnit\Framework\TestCase;

/**
Expand Down Expand Up @@ -58,66 +59,89 @@ public function provideInvalidValue(): \Generator
}
}

public function testBuildEmpty(): void
public function testBuildReturnsContainerWhenContainerBuilderDoesNotHaveDefinitions(): void
{
$builder = new ContainerBuilder();

$container = $builder->build();

self::assertInstanceOf(ContainerInterface::class, $container);
self::assertFalse($container->has('foo'));
}

public function testBuild(): void
public function testBuildReturnsContainerWhenContainerBuilderHasDefinitions(): void
{
$id = 'foo';
$definition = File::class;

$builder = new ContainerBuilder();

$builder->add('foo', File::class);
$builder->add($id, $definition);

$container = $builder->build();

self::assertInstanceOf(ContainerInterface::class, $container);
self::assertTrue($container->has($id));
self::assertInstanceOf($definition, $container->get($id));
}

public function testBuildWithDuplicates(): void
public function testBuildReturnsContainerWhenContainerBuilderHasOverriddenDefinitions(): void
{
$id = 'foo';
$definition = Number::class;

$builder = new ContainerBuilder();

$builder->add('foo', File::class);
$builder->add('foo', File::class);
$builder->add($id, File::class);
$builder->add($id, $definition);

$container = $builder->build();

self::assertInstanceOf(ContainerInterface::class, $container);
self::assertTrue($container->has($id));
self::assertInstanceOf($definition, $container->get($id));
}

public function testBuildWithObject(): void
public function testBuildReturnsContainerWhenContainerBuilderHasObjectAsDefinition(): void
{
$id = 'foo';
$definition = new File();

$builder = new ContainerBuilder();

$builder->add('foo', new File());
$builder->add($id, $definition);

$container = $builder->build();

self::assertInstanceOf(ContainerInterface::class, $container);
self::assertTrue($container->has($id));
self::assertSame($definition, $container->get($id));
}

public function testBuildWithCallable(): void
public function testBuildReturnsContainerWhenContainerBuilderHasCallableAsDefinition(): void
{
$id = 'foo';
$definition = static function (): File {
return new File();
};

$builder = new ContainerBuilder();

$builder->add('foo', static function () {
return new File();
});
$builder->add($id, $definition);

$container = $builder->build();

self::assertInstanceOf(ContainerInterface::class, $container);
self::assertTrue($container->has($id));
self::assertEquals($definition(), $container->get($id));
}

public function testBuildDefault(): void
public function testGetDefaultReturnsContainerWithDefaultExtensions(): void
{
$container = ContainerBuilder::getDefault();

self::assertInstanceOf(ContainerInterface::class, $container);
self::assertTrue($container->has(Extension\BarcodeExtension::class));
self::assertTrue($container->has(Extension\BloodExtension::class));
self::assertTrue($container->has(Extension\ColorExtension::class));
self::assertTrue($container->has(Extension\DateTimeExtension::class));
self::assertTrue($container->has(Extension\FileExtension::class));
self::assertTrue($container->has(Extension\NumberExtension::class));
self::assertTrue($container->has(Extension\UuidExtension::class));
self::assertTrue($container->has(Extension\VersionExtension::class));
}
}

0 comments on commit 976c9df

Please sign in to comment.