Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Improve tests for Definitions #295

Merged
merged 1 commit into from
Jul 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ on: # yamllint disable-line rule:truthy
- "main"

env:
MIN_COVERED_MSI: 96
MIN_MSI: 96
MIN_COVERED_MSI: 97
MIN_MSI: 97
PHP_EXTENSIONS: "mbstring"

jobs:
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
MIN_COVERED_MSI:=96
MIN_MSI:=96
MIN_COVERED_MSI:=97
MIN_MSI:=97

.PHONY: it
it: coding-standards static-code-analysis tests ## Runs the coding-standards, static-code-analysis, and tests targets
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2020 Andreas Möller
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/ergebnis/factory-bot
*/

namespace Ergebnis\FactoryBot\Test\Fixture\Definitions\DoesNotImplementDefinition;

use Ergebnis\FactoryBot\Definition;
use Ergebnis\FactoryBot\FixtureFactory;
use Ergebnis\FactoryBot\Test\Fixture;

final class OrganizationDefinition implements Definition
{
public function accept(FixtureFactory $fixtureFactory): void
{
$fixtureFactory->define(Fixture\FixtureFactory\Entity\Organization::class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2020 Andreas Möller
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/ergebnis/factory-bot
*/

namespace Ergebnis\FactoryBot\Test\Fixture\Definitions\DoesNotImplementDefinition;

use Ergebnis\FactoryBot\Definition;
use Ergebnis\FactoryBot\FixtureFactory;
use Ergebnis\FactoryBot\Test\Fixture;

final class UserDefinition implements Definition
{
public function accept(FixtureFactory $fixtureFactory): void
{
$fixtureFactory->define(Fixture\FixtureFactory\Entity\User::class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2020 Andreas Möller
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/ergebnis/factory-bot
*/

namespace Ergebnis\FactoryBot\Test\Fixture\Definitions\ImplementsDefinition;

use Ergebnis\FactoryBot\Definition;
use Ergebnis\FactoryBot\FixtureFactory;
use Ergebnis\FactoryBot\Test\Fixture;

final class OrganizationDefinition implements Definition
{
public function accept(FixtureFactory $fixtureFactory): void
{
$fixtureFactory->define(Fixture\FixtureFactory\Entity\Organization::class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2020 Andreas Möller
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/ergebnis/factory-bot
*/

namespace Ergebnis\FactoryBot\Test\Fixture\Definitions\ImplementsDefinition;

use Ergebnis\FactoryBot\Definition;
use Ergebnis\FactoryBot\FixtureFactory;
use Ergebnis\FactoryBot\Test\Fixture;

final class UserDefinition implements Definition
{
public function accept(FixtureFactory $fixtureFactory): void
{
$fixtureFactory->define(Fixture\FixtureFactory\Entity\User::class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2020 Andreas Möller
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/ergebnis/factory-bot
*/

namespace Ergebnis\FactoryBot\Test\Fixture\Definitions\ImplementsDefinitionButHasPrivateConstructor;

use Ergebnis\FactoryBot\Definition;
use Ergebnis\FactoryBot\FixtureFactory;
use Ergebnis\FactoryBot\Test\Fixture;

final class OrganizationDefinition implements Definition
{
public function accept(FixtureFactory $fixtureFactory): void
{
$fixtureFactory->define(Fixture\FixtureFactory\Entity\Organization::class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2020 Andreas Möller
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/ergebnis/factory-bot
*/

namespace Ergebnis\FactoryBot\Test\Fixture\Definitions\ImplementsDefinitionButHasPrivateConstructor;

use Ergebnis\FactoryBot\Definition;
use Ergebnis\FactoryBot\FixtureFactory;
use Ergebnis\FactoryBot\Test\Fixture;

final class UserDefinition implements Definition
{
public function accept(FixtureFactory $fixtureFactory): void
{
$fixtureFactory->define(Fixture\FixtureFactory\Entity\User::class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2020 Andreas Möller
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/ergebnis/factory-bot
*/

namespace Ergebnis\FactoryBot\Test\Fixture\Definitions\ImplementsDefinitionButIsAbstract;

use Ergebnis\FactoryBot\Definition;
use Ergebnis\FactoryBot\FixtureFactory;
use Ergebnis\FactoryBot\Test\Fixture;

final class OrganizationDefinition implements Definition
{
public function accept(FixtureFactory $fixtureFactory): void
{
$fixtureFactory->define(Fixture\FixtureFactory\Entity\Organization::class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2020 Andreas Möller
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/ergebnis/factory-bot
*/

namespace Ergebnis\FactoryBot\Test\Fixture\Definitions\ImplementsDefinitionButIsAbstract;

use Ergebnis\FactoryBot\Definition;
use Ergebnis\FactoryBot\FixtureFactory;
use Ergebnis\FactoryBot\Test\Fixture;

final class UserDefinition implements Definition
{
public function accept(FixtureFactory $fixtureFactory): void
{
$fixtureFactory->define(Fixture\FixtureFactory\Entity\User::class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2020 Andreas Möller
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/ergebnis/factory-bot
*/

namespace Ergebnis\FactoryBot\Test\Fixture\Definitions\ImplementsDefinitionButThrowsExceptionDuringConstruction;

use Ergebnis\FactoryBot\Definition;
use Ergebnis\FactoryBot\FixtureFactory;
use Ergebnis\FactoryBot\Test\Fixture;

final class OrganizationDefinition implements Definition
{
public function accept(FixtureFactory $fixtureFactory): void
{
$fixtureFactory->define(Fixture\FixtureFactory\Entity\Organization::class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2020 Andreas Möller
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/ergebnis/factory-bot
*/

namespace Ergebnis\FactoryBot\Test\Fixture\Definitions\ImplementsDefinitionButThrowsExceptionDuringConstruction;

use Ergebnis\FactoryBot\Definition;
use Ergebnis\FactoryBot\FixtureFactory;
use Ergebnis\FactoryBot\Test\Fixture;

final class UserDefinition implements Definition
{
public function accept(FixtureFactory $fixtureFactory): void
{
$fixtureFactory->define(Fixture\FixtureFactory\Entity\User::class);
}
}
33 changes: 29 additions & 4 deletions test/Unit/DefinitionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Ergebnis\FactoryBot\Test\Unit;

use Ergebnis\FactoryBot\Definitions;
use Ergebnis\FactoryBot\EntityDefinition;
use Ergebnis\FactoryBot\Exception;
use Ergebnis\FactoryBot\FixtureFactory;
use Ergebnis\FactoryBot\Test\Fixture;
Expand Down Expand Up @@ -50,7 +51,13 @@ public function testInIgnoresClassesWhichDoNotImplementProviderInterface(): void

$definitions->registerWith($fixtureFactory);

self::assertSame([], $fixtureFactory->definitions());
$registeredDefinitions = $fixtureFactory->definitions();

self::assertCount(2, $registeredDefinitions);
self::assertContainsOnly(EntityDefinition::class, $registeredDefinitions);
self::assertArrayHasKey(Fixture\FixtureFactory\Entity\Organization::class, $registeredDefinitions);
self::assertArrayNotHasKey(Fixture\FixtureFactory\Entity\Repository::class, $registeredDefinitions);
self::assertArrayHasKey(Fixture\FixtureFactory\Entity\User::class, $registeredDefinitions);
}

public function testInIgnoresDefinitionsThatAreAbstract(): void
Expand All @@ -64,7 +71,13 @@ public function testInIgnoresDefinitionsThatAreAbstract(): void

$definitions->registerWith($fixtureFactory);

self::assertSame([], $fixtureFactory->definitions());
$registeredDefinitions = $fixtureFactory->definitions();

self::assertCount(2, $registeredDefinitions);
self::assertContainsOnly(EntityDefinition::class, $registeredDefinitions);
self::assertArrayHasKey(Fixture\FixtureFactory\Entity\Organization::class, $registeredDefinitions);
self::assertArrayNotHasKey(Fixture\FixtureFactory\Entity\Repository::class, $registeredDefinitions);
self::assertArrayHasKey(Fixture\FixtureFactory\Entity\User::class, $registeredDefinitions);
}

public function testInIgnoresDefinitionsThatHavePrivateConstructors(): void
Expand All @@ -78,7 +91,13 @@ public function testInIgnoresDefinitionsThatHavePrivateConstructors(): void

$definitions->registerWith($fixtureFactory);

self::assertSame([], $fixtureFactory->definitions());
$registeredDefinitions = $fixtureFactory->definitions();

self::assertCount(2, $registeredDefinitions);
self::assertContainsOnly(EntityDefinition::class, $registeredDefinitions);
self::assertArrayHasKey(Fixture\FixtureFactory\Entity\Organization::class, $registeredDefinitions);
self::assertArrayNotHasKey(Fixture\FixtureFactory\Entity\Repository::class, $registeredDefinitions);
self::assertArrayHasKey(Fixture\FixtureFactory\Entity\User::class, $registeredDefinitions);
}

public function testInThrowsInvalidDefinitionExceptionWhenExceptionIsThrownDuringInstantiationOfDefinition(): void
Expand All @@ -99,6 +118,12 @@ public function testInAcceptsDefinitionsThatHaveNoIssues(): void

$definitions->registerWith($fixtureFactory);

self::assertArrayHasKey(Fixture\FixtureFactory\Entity\Repository::class, $fixtureFactory->definitions());
$registeredDefinitions = $fixtureFactory->definitions();

self::assertCount(3, $registeredDefinitions);
self::assertContainsOnly(EntityDefinition::class, $registeredDefinitions);
self::assertArrayHasKey(Fixture\FixtureFactory\Entity\Organization::class, $registeredDefinitions);
self::assertArrayHasKey(Fixture\FixtureFactory\Entity\Repository::class, $registeredDefinitions);
self::assertArrayHasKey(Fixture\FixtureFactory\Entity\User::class, $registeredDefinitions);
}
}