-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Test\Ebln\PHPStan\EnforceFactory; | ||
|
||
use Ebln\PHPStan\EnforceFactory\ForceFactoryRule; | ||
use PHPStan\Reflection\ReflectionProvider; | ||
use PHPStan\Rules\Rule; | ||
use PHPStan\Testing\RuleTestCase; | ||
|
||
/** | ||
* @requires PHP >= 8.0 | ||
* @extends RuleTestCase<ForceFactoryRule> | ||
*/ | ||
class MixedForceFactoryRuleTest extends RuleTestCase | ||
{ | ||
public function testAttributeFactory(): void | ||
{ | ||
$this->analyse( | ||
[__DIR__ . '/dataMixed/AttributeFactory.php'], | ||
[ | ||
['Test\Ebln\PHPStan\EnforceFactory\dataMixed\code\MismatchedProduct has either no factories defined or a conflict between interface and attribute!', 25], | ||
] | ||
); | ||
} | ||
|
||
public function testRogueAttributeFactory(): void | ||
{ | ||
$this->analyse([__DIR__ . '/dataMixed/RogueAttributeFactory.php'], [ | ||
['Test\Ebln\PHPStan\EnforceFactory\dataMixed\code\AttributeProduct must be instantiated by Test\Ebln\PHPStan\EnforceFactory\dataMixed\AttributeFactory!', 14], | ||
['Test\Ebln\PHPStan\EnforceFactory\dataMixed\code\MixedProduct must be instantiated by Test\Ebln\PHPStan\EnforceFactory\dataMixed\AttributeFactory or Test\Ebln\PHPStan\EnforceFactory\dataMixed\ForcedFactory!', 19], | ||
|
||
]); | ||
} | ||
|
||
protected function getRule(): Rule | ||
{ | ||
return new ForceFactoryRule(self::getContainer()->getByType(ReflectionProvider::class)); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Test\Ebln\PHPStan\EnforceFactory\dataMixed; | ||
|
||
use Test\Ebln\PHPStan\EnforceFactory\dataMixed\code\AttributeProduct; | ||
use Test\Ebln\PHPStan\EnforceFactory\dataMixed\code\MismatchedProduct; | ||
use Test\Ebln\PHPStan\EnforceFactory\dataMixed\code\MixedProduct; | ||
|
||
class AttributeFactory | ||
{ | ||
public function allowedAttribute(): void | ||
{ | ||
$test = new AttributeProduct(); | ||
} | ||
|
||
public function allowedMix(): void | ||
{ | ||
$test = new MixedProduct(); | ||
} | ||
|
||
public function failingMismatch(): void | ||
{ | ||
$test = new MismatchedProduct(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Test\Ebln\PHPStan\EnforceFactory\dataMixed; | ||
|
||
class ForcedFactory | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Test\Ebln\PHPStan\EnforceFactory\dataMixed; | ||
|
||
use Test\Ebln\PHPStan\EnforceFactory\dataMixed\code\AttributeProduct; | ||
use Test\Ebln\PHPStan\EnforceFactory\dataMixed\code\MixedProduct; | ||
|
||
class RogueAttributeFactory | ||
{ | ||
public function forbiddenAttribute(): void | ||
{ | ||
$test = new AttributeProduct(); | ||
} | ||
|
||
public function forbiddenMix(): void | ||
{ | ||
$test = new MixedProduct(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Test\Ebln\PHPStan\EnforceFactory\dataMixed\code; | ||
|
||
use Ebln\PHPStan\EnforceFactory\ForceFactory; | ||
use Test\Ebln\PHPStan\EnforceFactory\dataMixed\AttributeFactory; | ||
|
||
#[ForceFactory(AttributeFactory::class)] | ||
class AttributeProduct | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Test\Ebln\PHPStan\EnforceFactory\dataMixed\code; | ||
|
||
use Ebln\PHPStan\EnforceFactory\ForceFactory; | ||
use Ebln\PHPStan\EnforceFactory\ForceFactoryInterface; | ||
use Test\Ebln\PHPStan\EnforceFactory\dataMixed\AttributeFactory; | ||
use Test\Ebln\PHPStan\EnforceFactory\dataMixed\ForcedFactory; | ||
|
||
#[ForceFactory(AttributeFactory::class)] | ||
class MismatchedProduct implements ForceFactoryInterface | ||
{ | ||
public static function getFactories(): array | ||
{ | ||
return [ForcedFactory::class, AttributeFactory::class]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Test\Ebln\PHPStan\EnforceFactory\dataMixed\code; | ||
|
||
use Ebln\PHPStan\EnforceFactory\ForceFactory; | ||
use Ebln\PHPStan\EnforceFactory\ForceFactoryInterface; | ||
use Test\Ebln\PHPStan\EnforceFactory\dataMixed\AttributeFactory; | ||
use Test\Ebln\PHPStan\EnforceFactory\dataMixed\ForcedFactory; | ||
|
||
#[ForceFactory(ForcedFactory::class, AttributeFactory::class)] | ||
class MixedProduct implements ForceFactoryInterface | ||
{ | ||
public static function getFactories(): array | ||
{ | ||
return [ForcedFactory::class, AttributeFactory::class]; | ||
} | ||
} | ||
|