Skip to content

Commit

Permalink
Merge pull request #8 from localheinz/fix/fixture
Browse files Browse the repository at this point in the history
Fix: Do not reuse test fixtures
  • Loading branch information
localheinz authored Nov 14, 2018
2 parents 8c544dc + a73ff85 commit 7f1a019
Show file tree
Hide file tree
Showing 21 changed files with 224 additions and 32 deletions.
5 changes: 3 additions & 2 deletions test/AutoReview/TestCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Localheinz\PHPStan\Rules\Test\AutoReview;

use Localheinz\PHPStan\Rules\Test\Integration;
use Localheinz\PHPStan\Rules\Test\Fixture;
use Localheinz\Test\Util\Helper;
use PHPUnit\Framework;

Expand All @@ -27,7 +27,8 @@ final class TestCodeTest extends Framework\TestCase
public function testTestClassesAreAbstractOrFinal(): void
{
$this->assertClassesAreAbstractOrFinal(__DIR__ . '/..', [
Integration\Classes\Fixture\NeitherAbstractNorFinalClass::class,
Fixture\Classes\AbstractOrFinalRule\NeitherAbstractNorFinalClass::class,
Fixture\Classes\FinalRule\NeitherAbstractNorFinalClass::class,
]);
}
}
18 changes: 18 additions & 0 deletions test/Fixture/Classes/AbstractOrFinalRule/AbstractClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

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

namespace Localheinz\PHPStan\Rules\Test\Fixture\Classes\AbstractOrFinalRule;

abstract class AbstractClass
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

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

namespace Localheinz\PHPStan\Rules\Test\Fixture\Classes\AbstractOrFinalRule;

abstract class AbstractClassWithAnonymousClass
{
public function create()
{
return new class() {
public function __toString(): string
{
return 'Hmm';
}
};
}
}
18 changes: 18 additions & 0 deletions test/Fixture/Classes/AbstractOrFinalRule/ExampleInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

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

namespace Localheinz\PHPStan\Rules\Test\Fixture\Classes\AbstractOrFinalRule;

interface ExampleInterface
{
}
18 changes: 18 additions & 0 deletions test/Fixture/Classes/AbstractOrFinalRule/ExampleTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

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

namespace Localheinz\PHPStan\Rules\Test\Fixture\Classes\AbstractOrFinalRule;

trait ExampleTrait
{
}
18 changes: 18 additions & 0 deletions test/Fixture/Classes/AbstractOrFinalRule/FinalClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

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

namespace Localheinz\PHPStan\Rules\Test\Fixture\Classes\AbstractOrFinalRule;

final class FinalClass
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

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

namespace Localheinz\PHPStan\Rules\Test\Fixture\Classes\AbstractOrFinalRule;

final class FinalClassWithAnonymousClass
{
public function create()
{
return new class() {
public function __toString(): string
{
return 'Hmm';
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

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

namespace Localheinz\PHPStan\Rules\Test\Fixture\Classes\AbstractOrFinalRule;

class NeitherAbstractNorFinalClass
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

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

namespace Localheinz\PHPStan\Rules\Test\Fixture\Classes\AbstractOrFinalRule;

trait TraitWithAnonymousClass
{
public function create()
{
return new class() {
public function __toString(): string
{
return 'Hmm';
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @see https://github.com/localheinz/phpstan-rules
*/

namespace Localheinz\PHPStan\Rules\Test\Integration\Classes\Fixture;
namespace Localheinz\PHPStan\Rules\Test\Fixture\Classes\FinalRule;

abstract class AbstractClass
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @see https://github.com/localheinz/phpstan-rules
*/

namespace Localheinz\PHPStan\Rules\Test\Integration\Classes\Fixture;
namespace Localheinz\PHPStan\Rules\Test\Fixture\Classes\FinalRule;

abstract class AbstractClassWithAnonymousClass
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @see https://github.com/localheinz/phpstan-rules
*/

namespace Localheinz\PHPStan\Rules\Test\Integration\Classes\Fixture;
namespace Localheinz\PHPStan\Rules\Test\Fixture\Classes\FinalRule;

interface ExampleInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @see https://github.com/localheinz/phpstan-rules
*/

namespace Localheinz\PHPStan\Rules\Test\Integration\Classes\Fixture;
namespace Localheinz\PHPStan\Rules\Test\Fixture\Classes\FinalRule;

trait ExampleTrait
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @see https://github.com/localheinz/phpstan-rules
*/

namespace Localheinz\PHPStan\Rules\Test\Integration\Classes\Fixture;
namespace Localheinz\PHPStan\Rules\Test\Fixture\Classes\FinalRule;

final class FinalClass
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @see https://github.com/localheinz/phpstan-rules
*/

namespace Localheinz\PHPStan\Rules\Test\Integration\Classes\Fixture;
namespace Localheinz\PHPStan\Rules\Test\Fixture\Classes\FinalRule;

final class FinalClassWithAnonymousClass
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @see https://github.com/localheinz/phpstan-rules
*/

namespace Localheinz\PHPStan\Rules\Test\Integration\Classes\Fixture;
namespace Localheinz\PHPStan\Rules\Test\Fixture\Classes\FinalRule;

class NeitherAbstractNorFinalClass
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @see https://github.com/localheinz/phpstan-rules
*/

namespace Localheinz\PHPStan\Rules\Test\Integration\Classes\Fixture;
namespace Localheinz\PHPStan\Rules\Test\Fixture\Classes\FinalRule;

trait TraitWithAnonymousClass
{
Expand Down
18 changes: 18 additions & 0 deletions test/Fixture/Classes/FinalRule/script-with-anonymous-class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2018 Andreas Möller.
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*
* @see https://github.com/localheinz/phpstan-rules
*/
$foo = new class() {
public function __toString(): string
{
return 'Hmm';
}
};
21 changes: 11 additions & 10 deletions test/Integration/Classes/AbstractOrFinalRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Localheinz\PHPStan\Rules\Test\Integration\Classes;

use Localheinz\PHPStan\Rules\Classes\AbstractOrFinalRule;
use Localheinz\PHPStan\Rules\Test\Fixture;
use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;

Expand All @@ -26,8 +27,8 @@ public function testNotClasses(): void
{
$this->analyse(
[
__DIR__ . '/Fixture/ExampleInterface.php',
__DIR__ . '/Fixture/ExampleTrait.php',
__DIR__ . '/../../Fixture/Classes/AbstractOrFinalRule/ExampleInterface.php',
__DIR__ . '/../../Fixture/Classes/AbstractOrFinalRule/ExampleTrait.php',
],
[]
);
Expand All @@ -37,8 +38,8 @@ public function testAbstractOrFinalClasses(): void
{
$this->analyse(
[
__DIR__ . '/Fixture/AbstractClass.php',
__DIR__ . '/Fixture/FinalClass.php',
__DIR__ . '/../../Fixture/Classes/AbstractOrFinalRule/AbstractClass.php',
__DIR__ . '/../../Fixture/Classes/AbstractOrFinalRule/FinalClass.php',
],
[]
);
Expand All @@ -48,10 +49,10 @@ public function testConstructsWithAnonymousClasses(): void
{
$this->analyse(
[
__DIR__ . '/Fixture/AbstractClassWithAnonymousClass.php',
__DIR__ . '/Fixture/FinalClassWithAnonymousClass.php',
__DIR__ . '/Fixture/script-with-anonymous-class.php',
__DIR__ . '/Fixture/TraitWithAnonymousClass.php',
__DIR__ . '/../../Fixture/Classes/AbstractOrFinalRule/AbstractClassWithAnonymousClass.php',
__DIR__ . '/../../Fixture/Classes/AbstractOrFinalRule/FinalClassWithAnonymousClass.php',
__DIR__ . '/../../Fixture/Classes/AbstractOrFinalRule/script-with-anonymous-class.php',
__DIR__ . '/../../Fixture/Classes/AbstractOrFinalRule/TraitWithAnonymousClass.php',
],
[]
);
Expand All @@ -61,13 +62,13 @@ public function testNeitherAbstractNorFinalClass(): void
{
$this->analyse(
[
__DIR__ . '/Fixture/NeitherAbstractNorFinalClass.php',
__DIR__ . '/../../Fixture/Classes/AbstractOrFinalRule/NeitherAbstractNorFinalClass.php',
],
[
[
\sprintf(
'Class "%s" should be marked as abstract or final.',
Fixture\NeitherAbstractNorFinalClass::class
Fixture\Classes\AbstractOrFinalRule\NeitherAbstractNorFinalClass::class
),
16,
],
Expand Down
Loading

0 comments on commit 7f1a019

Please sign in to comment.