-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from mediact/issue/25
1.0.5 - Fix issue #25 - Out of memory error
- Loading branch information
Showing
10 changed files
with
589 additions
and
38 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
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,44 @@ | ||
<?php | ||
/** | ||
* Copyright MediaCT. All rights reserved. | ||
* https://www.mediact.nl | ||
*/ | ||
|
||
namespace Mediact\DependencyGuard\Reflection; | ||
|
||
use Roave\BetterReflection\BetterReflection; | ||
use Roave\BetterReflection\Reflection\ReflectionClass; | ||
|
||
trait ReflectionTrait | ||
{ | ||
/** @var BetterReflection */ | ||
private static $reflectionEnvironment; | ||
|
||
/** | ||
* Get the current reflection environment. | ||
* | ||
* @return BetterReflection | ||
*/ | ||
private static function getReflectionEnvironment(): BetterReflection | ||
{ | ||
if (self::$reflectionEnvironment === null) { | ||
self::$reflectionEnvironment = new BetterReflection(); | ||
} | ||
|
||
return self::$reflectionEnvironment; | ||
} | ||
|
||
/** | ||
* Get the reflection for the given class name. | ||
* | ||
* @param string $className | ||
* | ||
* @return ReflectionClass | ||
*/ | ||
public function getClassReflection(string $className): ReflectionClass | ||
{ | ||
return static::getReflectionEnvironment() | ||
->classReflector() | ||
->reflect($className); | ||
} | ||
} |
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,33 @@ | ||
<?php | ||
/** | ||
* Copyright MediaCT. All rights reserved. | ||
* https://www.mediact.nl | ||
*/ | ||
|
||
namespace Mediact\DependencyGuard\Tests\Reflection; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Mediact\DependencyGuard\Reflection\ReflectionTrait; | ||
use Roave\BetterReflection\Reflection\ReflectionClass; | ||
|
||
/** | ||
* @coversDefaultClass \Mediact\DependencyGuard\Reflection\ReflectionTrait | ||
*/ | ||
class ReflectionTraitTest extends TestCase | ||
{ | ||
/** | ||
* @return void | ||
* @covers ::getClassReflection | ||
* @covers ::getReflectionEnvironment | ||
*/ | ||
public function testGetClassReflection(): void | ||
{ | ||
/** @var ReflectionTrait $subject */ | ||
$subject = $this->getMockForTrait(ReflectionTrait::class); | ||
|
||
$this->assertInstanceOf( | ||
ReflectionClass::class, | ||
$subject->getClassReflection(__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,84 @@ | ||
<?php | ||
/** | ||
* Copyright MediaCT. All rights reserved. | ||
* https://www.mediact.nl | ||
*/ | ||
|
||
namespace Mediact\DependencyGuard\Tests\Regression; | ||
|
||
use ReflectionObject; | ||
use Symfony\Component\Process\Process; | ||
use Composer\Util\Filesystem; | ||
|
||
trait ComposerTestEnvironmentTrait | ||
{ | ||
/** @var string */ | ||
private $workingDirectory; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
private function getWorkingDirectory(): string | ||
{ | ||
if ($this->workingDirectory === null) { | ||
$reflection = new ReflectionObject($this); | ||
|
||
$this->workingDirectory = dirname($reflection->getFileName()); | ||
} | ||
|
||
return $this->workingDirectory; | ||
} | ||
|
||
/** | ||
* Create a composer process for the given command. | ||
* | ||
* @param string $command | ||
* @param string ...$arguments | ||
* | ||
* @return Process | ||
*/ | ||
protected function createComposerProcess( | ||
string $command, | ||
string ...$arguments | ||
): Process { | ||
return new Process( | ||
array_merge( | ||
[ | ||
trim(`which composer` ?? `which composer.phar`), | ||
$command, | ||
], | ||
$arguments, | ||
[ | ||
'--quiet', | ||
'--working-dir', | ||
$this->getWorkingDirectory() | ||
] | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function setUp(): void | ||
{ | ||
$process = $this->createComposerProcess('install'); | ||
|
||
if ($process->run() !== 0) { | ||
self::markTestSkipped( | ||
$process->getErrorOutput() | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function tearDown(): void | ||
{ | ||
$filesystem = new Filesystem(); | ||
$filesystem->removeDirectory( | ||
$this->getWorkingDirectory() . DIRECTORY_SEPARATOR . 'vendor' | ||
); | ||
} | ||
} |
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,45 @@ | ||
<?php | ||
/** | ||
* Copyright MediaCT. All rights reserved. | ||
* https://www.mediact.nl | ||
*/ | ||
|
||
namespace Mediact\DependencyGuard\Tests\Regression\Issue25; | ||
|
||
use Mediact\DependencyGuard\Tests\Regression\ComposerTestEnvironmentTrait; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Process\Process; | ||
|
||
/** | ||
* @see https://github.com/mediact/dependency-guard/issues/25 | ||
*/ | ||
class Issue25Test extends TestCase | ||
{ | ||
use ComposerTestEnvironmentTrait; | ||
|
||
/** | ||
* @return void | ||
* @coversNothing | ||
*/ | ||
public function testNoOutOfMemoryError(): void | ||
{ | ||
$process = new Process( | ||
[ | ||
PHP_BINARY, | ||
'-d', | ||
'memory_limit=25M', | ||
'../../../bin/dependency-guard' | ||
], | ||
__DIR__ | ||
); | ||
|
||
// The exit code of the process is of no concern to the issue. | ||
$process->run(); | ||
|
||
$this->assertNotContains( | ||
'Allowed memory size', | ||
$process->getErrorOutput(), | ||
'Dependency guard ran out of memory.' | ||
); | ||
} | ||
} |
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,11 @@ | ||
{ | ||
"name": "issue25/test", | ||
"require": { | ||
"php-twinfield/twinfield": "dev-master#04c1b248efc9268db2ad173a9305fa9c21970df8" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"PhpTwinfield\\": "vendor/php-twinfield/twinfield/src" | ||
} | ||
} | ||
} |
Oops, something went wrong.