Skip to content
This repository has been archived by the owner on Aug 29, 2020. It is now read-only.

Commit

Permalink
Merge pull request #3 from localheinz/fix/private
Browse files Browse the repository at this point in the history
Fix: Ignore definitions with private constructors
  • Loading branch information
localheinz authored May 31, 2017
2 parents 8723191 + b2750d0 commit 429a329
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Definitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static function in($directory)
continue;
}

if (!$reflection->isSubclassOf(Definition::class) || $reflection->isAbstract()) {
if (!$reflection->isSubclassOf(Definition::class) || !$reflection->isInstantiable()) {
continue;
}

Expand Down
30 changes: 30 additions & 0 deletions test/Unit/Asset/Definition/PrivateConstructor/UserDefinition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/**
* Copyright (c) 2017 Andreas Möller
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* @link https://github.com/localheinz/factory-girl-definition
*/

namespace Localheinz\FactoryGirl\Definition\Test\Unit\Asset\Definition\PrivateConstructor;

use FactoryGirl\Provider\Doctrine\FixtureFactory;
use Localheinz\FactoryGirl\Definition\Definition;

/**
* Is not acceptable as it has a private constructor.
*/
final class UserDefinition implements Definition
{
private function __construct()
{
}

public function accept(FixtureFactory $factory)
{
$factory->defineEntity('Foo');
}
}
11 changes: 11 additions & 0 deletions test/Unit/DefinitionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ public function testInIgnoresClassesWhichAreAbstract()
Definitions::in(__DIR__ . '/Asset/Definition/IsAbstract')->registerWith($fixtureFactory);
}

public function testInIgnoresClassesWhichHavePrivateConstructors()
{
$fixtureFactory = $this->createFixtureFactoryMock();

$fixtureFactory
->expects($this->never())
->method($this->anything());

Definitions::in(__DIR__ . '/Asset/Definition/PrivateConstructor')->registerWith($fixtureFactory);
}

public function testInAcceptsClassesWhichAreAcceptable()
{
$fixtureFactory = $this->createFixtureFactoryMock();
Expand Down

0 comments on commit 429a329

Please sign in to comment.