Skip to content

Commit

Permalink
Load all library files automatically in tests
Browse files Browse the repository at this point in the history
Because it shouldn't be this easy to forget to load a new file. Some files in the libs dir were more a test subject so they were moved to src.
  • Loading branch information
spaze committed Jul 1, 2023
1 parent 18ee549 commit 60cf2b9
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 43 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
},
"scripts": {
"lint": "vendor/bin/parallel-lint --colors src/ tests/",
"lint-7.x": "vendor/bin/parallel-lint --colors src/ tests/ --exclude tests/libs/TypesEverywhere.php --exclude tests/src/disallowed/functionCallsNamedParams.php --exclude tests/src/disallowed-allow/functionCallsNamedParams.php --exclude tests/src/disallowed/attributeUsages.php --exclude tests/src/disallowed-allow/attributeUsages.php",
"lint-8.0": "vendor/bin/parallel-lint --colors src/ tests/ --exclude tests/libs/TypesEverywhere.php",
"lint-7.x": "vendor/bin/parallel-lint --colors src/ tests/ --exclude tests/src/TypesEverywhere.php --exclude tests/src/disallowed/functionCallsNamedParams.php --exclude tests/src/disallowed-allow/functionCallsNamedParams.php --exclude tests/src/disallowed/attributeUsages.php --exclude tests/src/disallowed-allow/attributeUsages.php",
"lint-8.0": "vendor/bin/parallel-lint --colors src/ tests/ --exclude tests/src/TypesEverywhere.php",
"lint-neon": "vendor/bin/neon-lint .",
"phpcs": "vendor/bin/phpcs src/ tests/",
"cs-fix": "vendor/bin/phpcbf src/ tests/",
Expand Down
16 changes: 8 additions & 8 deletions tests/Calls/FunctionCallsInMultipleNamespacesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,36 +52,36 @@ protected function getRule(): Rule
public function testRule(): void
{
// Based on the configuration above, in this file:
$this->analyse([__DIR__ . '/../libs/FunctionInMultipleNamespaces.php'], [
$this->analyse([__DIR__ . '/../src/FunctionInMultipleNamespaces.php'], [
[
// expect this error message:
'Calling __() (as alias()) is forbidden, use MyNamespace\__ instead',
// on this line:
18,
20,
],
[
'Calling MyNamespace\__() (as __()) is forbidden, ha ha ha nope',
23,
26,
],
[
'Calling printf() is forbidden, because reasons',
26,
30,
],
[
'Calling printf() is forbidden, because reasons',
27,
31,
],
[
'Calling MyNamespace\__() (as alias()) is forbidden, ha ha ha nope',
35,
39,
],
[
'Calling printf() is forbidden, because reasons',
36,
40,
],
[
'Calling printf() is forbidden, because reasons',
37,
41,
],
]);
}
Expand Down
14 changes: 7 additions & 7 deletions tests/Usages/AttributeUsagesAllowParamsMultipleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function getRule(): Rule
AttributeEntity::class,
],
'allowIn' => [
'../libs/ClassWithAttributesAllow.php',
'../disallowed-allow/ClassWithAttributesAllow.php',
],
'allowParamsAnywhereAnyValue' => [
[
Expand All @@ -57,26 +57,26 @@ protected function getRule(): Rule
public function testRule(): void
{
// Based on the configuration above, in this file:
$this->analyse([__DIR__ . '/../libs/ClassWithAttributes.php'], [
$this->analyse([__DIR__ . '/../disallowed/ClassWithAttributes.php'], [
[
// expect this error message:
'Attribute Attributes\AttributeEntity is forbidden, because reasons',
// on this line:
10,
9,
],
]);
$this->analyse([__DIR__ . '/../libs/ClassWithAttributesAllow.php'], [
$this->analyse([__DIR__ . '/../disallowed-allow/ClassWithAttributesAllow.php'], [
[
'Attribute Attributes\AttributeEntity is forbidden, because reasons',
10,
9,
],
[
'Attribute Attributes\AttributeEntity is forbidden, because reasons',
15,
14,
],
[
'Attribute Attributes\AttributeEntity is forbidden, because reasons',
22,
21,
],
]);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Usages/AttributeUsagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function getRule(): Rule
AttributeEntity::class,
],
'allowIn' => [
'../libs/ClassWithAttributesAllow.php',
'../src/disallowed-allow/ClassWithAttributesAllow.php',
],
'allowParamsAnywhereAnyValue' => [
[
Expand All @@ -48,15 +48,15 @@ protected function getRule(): Rule
public function testRule(): void
{
// Based on the configuration above, in this file:
$this->analyse([__DIR__ . '/../libs/ClassWithAttributes.php'], [
$this->analyse([__DIR__ . '/../disallowed/ClassWithAttributes.php'], [
[
// expect this error message:
'Attribute Attributes\AttributeEntity is forbidden, because reasons',
// on this line:
10,
9,
],
]);
$this->analyse([__DIR__ . '/../libs/ClassWithAttributesAllow.php'], []);
$this->analyse([__DIR__ . '/../disallowed-allow/ClassWithAttributesAllow.php'], []);
}

}
2 changes: 1 addition & 1 deletion tests/Usages/NamespaceUsagesTypesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected function getRule(): Rule
public function testRule(): void
{
// Based on the configuration above, in this file:
$this->analyse([__DIR__ . '/../libs/TypesEverywhere.php'], [
$this->analyse([__DIR__ . '/../src/TypesEverywhere.php'], [
[
// expect this error message:
'Namespace Waldo\Quux\Blade is forbidden, do androids dream of electric sheep?',
Expand Down
17 changes: 7 additions & 10 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
declare(strict_types = 1);

require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/libs/Bar.php';
require_once __DIR__ . '/libs/Blade.php';
require_once __DIR__ . '/libs/Constructor.php';
require_once __DIR__ . '/libs/Functions.php';
require_once __DIR__ . '/libs/Inheritance.php';
require_once __DIR__ . '/libs/Royale.php';
require_once __DIR__ . '/libs/SomeInterface.php';
require_once __DIR__ . '/libs/Option.php';
require_once __DIR__ . '/libs/TestTrait.php';
require_once __DIR__ . '/libs/Traits.php';

$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__ . '/libs', FilesystemIterator::SKIP_DOTS));
foreach ($iterator as $fileInfo) {
if ($fileInfo->getExtension() === 'php') {
require_once $fileInfo->getPathname();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
declare(strict_types=1);
declare(strict_types = 1);

namespace {

Expand All @@ -11,18 +11,22 @@ function __(): string

namespace MyNamespace {

// phpcs:ignore SlevomatCodingStandard.Namespaces.UseSpacing.IncorrectLinesCountAfterLastUse
use function __ as alias;


function __(): string
{
return alias();
}


function someOtherFn(): string
{
return __(); // The __ used here is MyNamespace\__
return __(); // The __ used here is MyNamespace\__
}


printf('oo');
\printf('oo');

Expand All @@ -37,4 +41,3 @@ function someOtherFn(): string
\printf('oo');

}

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
<?php
declare(strict_types = 1);

namespace libs;
namespace Attributes;

use Attributes\AttributeEntity;
use Waldo\Quux\Blade;

// disallowed, no $repositoryClass parameter specified
#[AttributeEntity]
#[\Attributes\AttributeEntity]
class ClassWithAttributesAllow
{

// disallowed, $repositoryClass present with any value
#[AttributeEntity(repositoryClass: UserRepository::class, readOnly: false)]
#[\Attributes\AttributeEntity(repositoryClass: \Attributes\UserRepository::class, readOnly: false)]
public function hasAvocado(): bool
{
}


// allowed, $repositoryClass present with any value
#[AttributeEntity(UserRepository::class)]
#[\Attributes\AttributeEntity(\Attributes\UserRepository::class)]
public function hasTuna(): bool
{
}


// allowed, $repositoryClass present with any value
#[AttributeEntity(Blade::class)]
#[\Attributes\AttributeEntity(Blade::class)]
public function hasKetchup(): bool
{
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php
declare(strict_types = 1);

namespace libs;
namespace Attributes;

use Attributes\AttributeEntity;
use Waldo\Quux\Blade;

// disallowed, no $repositoryClass parameter specified
Expand Down

0 comments on commit 60cf2b9

Please sign in to comment.