Skip to content

Commit

Permalink
Add test for production environment
Browse files Browse the repository at this point in the history
i.e. where on hasn't installed this rule
  • Loading branch information
ebln committed Jun 7, 2024
1 parent 3fd76c6 commit 79ebd45
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 9 deletions.
27 changes: 18 additions & 9 deletions tests/AttribForceFactoryRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,18 @@ public function testEmptyAllowedClasses(): void

public function testRogueFactory(): void
{
$offset = 1;
$this->analyse([__DIR__ . '/dataAttrib/RogueFactory.php'], [
[self::ERROR_MESSAGE, 15],
[self::ERROR_MESSAGE, 22],
[self::ERROR_MESSAGE, 29],
[self::ERROR_MESSAGE, 40],
[self::ERROR_MESSAGE, 40],
[self::ERROR_MESSAGE, 51],
[self::ERROR_MESSAGE, 56],
['Test\Ebln\PHPStan\EnforceFactory\dataAttrib\code\ExtendedProduct must be instantiated by Test\Ebln\PHPStan\EnforceFactory\dataAttrib\ForcedFactory or Test\Ebln\PHPStan\EnforceFactory\dataAttrib\TraitFactory!', 69],
[self::ERROR_MESSAGE, 95],
[self::ERROR_MESSAGE, 15 + $offset],
[self::ERROR_MESSAGE, 22 + $offset],
[self::ERROR_MESSAGE, 29 + $offset],
[self::ERROR_MESSAGE, 40 + $offset],
[self::ERROR_MESSAGE, 40 + $offset],
[self::ERROR_MESSAGE, 51 + $offset],
[self::ERROR_MESSAGE, 56 + $offset],
['Test\Ebln\PHPStan\EnforceFactory\dataAttrib\code\ExtendedProduct must be instantiated by Test\Ebln\PHPStan\EnforceFactory\dataAttrib\ForcedFactory or Test\Ebln\PHPStan\EnforceFactory\dataAttrib\TraitFactory!', 69 + $offset],
[self::ERROR_MESSAGE, 95 + $offset],
['Test\Ebln\PHPStan\EnforceFactory\dataAttrib\code\IndependentForcedFactoryProduct must be instantiated by Test\Ebln\PHPStan\EnforceFactory\dataAttrib\IndependentFactory!', 100 + $offset],
]);
}

Expand All @@ -72,6 +74,13 @@ public function testAllowedFactory(): void
$this->analyse([__DIR__ . '/dataAttrib/ForcedFactory.php'], []);
}

public function testIndependentFactory(): void
{
$offset = 1;
$this->analyse([__DIR__ . '/dataAttrib/IndependentFactory.php'], [
]);
}

protected function getRule(): Rule
{
return new ForceFactoryRule($this->createReflectionProvider());
Expand Down
15 changes: 15 additions & 0 deletions tests/dataAttrib/IndependentFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Test\Ebln\PHPStan\EnforceFactory\dataAttrib;

use Test\Ebln\PHPStan\EnforceFactory\dataAttrib\code\IndependentForcedFactoryProduct;

class IndependentFactory
{
public function independentClass(): IndependentForcedFactoryProduct
{
return new IndependentForcedFactoryProduct();
}
}
7 changes: 7 additions & 0 deletions tests/dataAttrib/RogueFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Test\Ebln\PHPStan\EnforceFactory\dataAttrib\code\ExtendedProduct;
use Test\Ebln\PHPStan\EnforceFactory\dataAttrib\code\ForcedFactoryProduct;
use Test\Ebln\PHPStan\EnforceFactory\dataAttrib\code\FreeProduct;
use Test\Ebln\PHPStan\EnforceFactory\dataAttrib\code\IndependentForcedFactoryProduct;

class RogueFactory
{
Expand Down Expand Up @@ -94,4 +95,10 @@ public static function staticClass(): ForcedFactoryProduct
{
return new ForcedFactoryProduct();
}

public function independentClass(): IndependentForcedFactoryProduct
{
return new IndependentForcedFactoryProduct();
}

}
13 changes: 13 additions & 0 deletions tests/dataAttrib/code/IndependentForcedFactoryProduct.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Test\Ebln\PHPStan\EnforceFactory\dataAttrib\code;

use Test\Ebln\PHPStan\EnforceFactory\dataAttrib\IndependentFactory;

#[\Ebln\PHPStan\EnforceFactory\ForceFactory(IndependentFactory::class)]
#[\INVALID\NOT\FOUND\ATTRIBUTE(IndependentFactory::class)]
class IndependentForcedFactoryProduct
{
}

0 comments on commit 79ebd45

Please sign in to comment.