Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"autoload-dev": {
"psr-4": {
"My\\Integration\\": "tests/integration/src",
"AdrianSuter\\Autoload\\Override\\": "tests/integration/src-override"
"AdrianSuter\\Autoload\\Override\\": "tests/integration/src-override",
"AdrianSuter\\Autoload\\Override\\Tests\\": "tests"
},
"classmap": [
"tests/integration/src/TestClassMapOverride"
Expand All @@ -37,12 +38,15 @@
"nikic/php-parser": "^4.3"
},
"require-dev": {
"phpunit/phpunit": "^7.0"
"phpunit/phpunit": "^7.0",
"squizlabs/php_codesniffer": "^3.5"
},
"scripts": {
"test": [
"@phpunit"
"@phpunit",
"@phpcs"
],
"phpunit": "phpunit"
"phpunit": "phpunit",
"phpcs": "phpcs"
}
}
17 changes: 17 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<ruleset name="PHP Autoload Override coding standard">
<description>PHP Autoload Override coding standard</description>

<!-- display progress -->
<arg value="p"/>
<!-- use colors in output -->
<arg name="colors"/>

<!-- inherit rules from: -->
<rule ref="PSR12"/>
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>

<!-- Paths to check -->
<file>src</file>
<file>tests</file>
</ruleset>
1 change: 1 addition & 0 deletions src/AutoloadCollection.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* PHP Autoload Override (https://github.com/adriansuter/php-autoload-override)
*
Expand Down
1 change: 1 addition & 0 deletions src/ClosureHandler.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* PHP Autoload Override (https://github.com/adriansuter/php-autoload-override)
*
Expand Down
5 changes: 3 additions & 2 deletions src/CodeConverter.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* PHP Autoload Override (https://github.com/adriansuter/php-autoload-override)
*
Expand Down Expand Up @@ -75,10 +76,10 @@ public function __construct(
?NodeFinder $nodeFinder = null
) {
$this->lexer = $lexer ?? new Emulative(
[
[
'usedAttributes' => ['comments', 'startLine', 'endLine', 'startTokenPos', 'endTokenPos'],
]
);
);

$this->parser = $parser ?? new Php7($this->lexer);

Expand Down
2 changes: 2 additions & 0 deletions src/FileStreamWrapper.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* PHP Autoload Override (https://github.com/adriansuter/php-autoload-override)
*
Expand Down Expand Up @@ -42,6 +43,7 @@
use function touch;
use function unlink;

// phpcs:disable PSR1.Methods.CamelCapsMethodName
class FileStreamWrapper
{
/**
Expand Down
1 change: 1 addition & 0 deletions src/Override.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* PHP Autoload Override (https://github.com/adriansuter/php-autoload-override)
*
Expand Down
4 changes: 3 additions & 1 deletion tests/AbstractIntegrationTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* PHP Autoload Override (https://github.com/adriansuter/php-autoload-override)
*
Expand All @@ -7,6 +8,8 @@

declare(strict_types=1);

namespace AdrianSuter\Autoload\Override\Tests;

use AdrianSuter\Autoload\Override\Override;
use PHPUnit\Framework\TestCase;

Expand All @@ -24,7 +27,6 @@ public static function setUpBeforeClass()
protected function setUp()
{
parent::setUp();

if (!$this->overrideApplied) {
$this->overrideApplied = true;
Override::apply(self::$classLoader, $this->getOverrideDeclarations());
Expand Down
3 changes: 3 additions & 0 deletions tests/AutoloadCollectionTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* PHP Autoload Override (https://github.com/adriansuter/php-autoload-override)
*
Expand All @@ -7,6 +8,8 @@

declare(strict_types=1);

namespace AdrianSuter\Autoload\Override\Tests;

use AdrianSuter\Autoload\Override\AutoloadCollection;
use PHPUnit\Framework\TestCase;

Expand Down
4 changes: 4 additions & 0 deletions tests/ClosureHandlerTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* PHP Autoload Override (https://github.com/adriansuter/php-autoload-override)
*
Expand All @@ -7,8 +8,11 @@

declare(strict_types=1);

namespace AdrianSuter\Autoload\Override\Tests;

use AdrianSuter\Autoload\Override\ClosureHandler;
use PHPUnit\Framework\TestCase;
use RuntimeException;

final class ClosureHandlerTest extends TestCase
{
Expand Down
4 changes: 3 additions & 1 deletion tests/CodeConverterTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* PHP Autoload Override (https://github.com/adriansuter/php-autoload-override)
*
Expand All @@ -7,6 +8,8 @@

declare(strict_types=1);

namespace AdrianSuter\Autoload\Override\Tests;

use AdrianSuter\Autoload\Override\CodeConverter;
use PHPUnit\Framework\TestCase;

Expand All @@ -15,7 +18,6 @@ class CodeConverterTest extends TestCase
public function testA()
{
$converter = new CodeConverter();

$this->assertEquals(
'<?php echo \foo\rand(0, 9);',
$converter->convert('<?php echo \rand(0, 9);', ['\rand' => 'foo\rand'])
Expand Down
5 changes: 5 additions & 0 deletions tests/FileStreamWrapperTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* PHP Autoload Override (https://github.com/adriansuter/php-autoload-override)
*
Expand All @@ -7,8 +8,12 @@

declare(strict_types=1);

namespace AdrianSuter\Autoload\Override\Tests;

use AdrianSuter\Autoload\Override\FileStreamWrapper;
use PHPUnit\Framework\TestCase;
use ReflectionProperty;
use RuntimeException;

final class FileStreamWrapperTest extends TestCase
{
Expand Down
14 changes: 8 additions & 6 deletions tests/IntegrationClassMapTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* PHP Autoload Override (https://github.com/adriansuter/php-autoload-override)
*
Expand All @@ -7,18 +8,22 @@

declare(strict_types=1);

namespace AdrianSuter\Autoload\Override\Tests;

class IntegrationClassMapTest extends AbstractIntegrationTest
{
protected function getOverrideDeclarations(): array
{
return [
\My\Integration\TestClassMapOverride\Calculator::class => [
'cos' => function (float $arg): float {

return \sin($arg);
},
],
'My\\Integration\\TestClassMapOverride\\' => [
'cos' => function (float $arg): float {

return $arg * 2;
},
]
Expand All @@ -28,24 +33,21 @@ protected function getOverrideDeclarations(): array
public function testCalculator()
{
$calculator = new \My\Integration\TestClassMapOverride\Calculator();

// Calls \cos() > Overridden by FQCN-declaration.
// Calls \cos() > Overridden by FQCN-declaration.
$this->assertEquals(\sin(\pi() / 2), $calculator->cos(\pi() / 2));
}

public function testGeometry()
{
$geometry = new \My\Integration\TestClassMapOverride\SubNamespace\Geometry();

// Calls \cos() > Overridden by FQNS-declaration.
// Calls \cos() > Overridden by FQNS-declaration.
$this->assertEquals(1, $geometry->cos(0.5));
}

public function testOtherCalculator()
{
$otherCalculator = new \My\Integration\TestClassMapOverride\OtherCalculator();

// Calls \cos() > Overridden by FQNS-declaration.
// Calls \cos() > Overridden by FQNS-declaration.
$this->assertEquals(2, $otherCalculator->cos(1));
}
}
Loading