-
Notifications
You must be signed in to change notification settings - Fork 3
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 #63: Added Production/Development environment option
- Loading branch information
Showing
144 changed files
with
1,180 additions
and
715 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
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
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,91 @@ | ||
<?php | ||
|
||
namespace Okapi\Aop\Tests; | ||
|
||
use Okapi\Aop\Core\AutoloadInterceptor\ClassLoader; | ||
use Okapi\Aop\Core\Cache\CachePaths; | ||
use Okapi\CodeTransformer\Core\DI; | ||
use Okapi\CodeTransformer\Core\StreamFilter; | ||
use Okapi\CodeTransformer\Core\StreamFilter\FilterInjector; | ||
use Okapi\Path\Path; | ||
use PHPUnit\Framework\Assert; | ||
use ReflectionProperty; | ||
|
||
trait ClassLoaderMockTrait | ||
{ | ||
private ?ClassLoader $classLoader = null; | ||
|
||
private function findClassMock(string $class): string | ||
{ | ||
if (!isset($this->classLoader)) { | ||
$this->findClassLoader(); | ||
} | ||
|
||
return $this->classLoader->findFile($class); | ||
} | ||
|
||
private function findOriginalClassMock(string $class): string | ||
{ | ||
if (!isset($this->classLoader)) { | ||
$this->findClassLoader(); | ||
} | ||
|
||
$original = new ReflectionProperty(ClassLoader::class, 'originalClassLoader'); | ||
$original = $original->getValue($this->classLoader); | ||
return $original->findFile($class); | ||
} | ||
|
||
private function findClassLoader(): void | ||
{ | ||
foreach (spl_autoload_functions() as $function) { | ||
if (is_array($function) && $function[0] instanceof ClassLoader) { | ||
$this->classLoader = $function[0]; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
public function assertWillBeWoven(string $className): void | ||
{ | ||
$originalFilePath = Path::resolve($this->findOriginalClassMock($className)); | ||
|
||
$wovenPath = | ||
FilterInjector::PHP_FILTER_READ . | ||
StreamFilter::FILTER_ID . '/resource=' . | ||
$originalFilePath; | ||
|
||
$filePathMock = $this->findClassMock($className); | ||
|
||
Assert::assertEquals( | ||
$wovenPath, | ||
$filePathMock, | ||
"$className will not be woven", | ||
); | ||
} | ||
|
||
public function assertAspectLoadedFromCache(string $className): void | ||
{ | ||
$filePath = $this->findOriginalClassMock($className); | ||
$cachePaths = DI::get(CachePaths::class); | ||
$cachePath = $cachePaths->getProxyCachePath($filePath); | ||
$filePathMock = $this->findClassMock($className); | ||
|
||
Assert::assertEquals( | ||
$cachePath, | ||
$filePathMock, | ||
"$className will not be loaded from cache", | ||
); | ||
} | ||
|
||
public function assertAspectNotApplied(string $className): void | ||
{ | ||
$originalFilePath = Path::resolve($this->findOriginalClassMock($className)); | ||
$filePathMock = $this->findClassMock($className); | ||
|
||
Assert::assertEquals( | ||
$originalFilePath, | ||
$filePathMock, | ||
"$className will be woven", | ||
); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
...ional/AdviceApplication/AdviceMatchingAbstractMethod/AdviceMatchingAbstractMethodTest.php
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,37 @@ | ||
<?php | ||
|
||
namespace Okapi\Aop\Tests\Functional\AdviceApplication\AdviceMatchingAbstractMethod; | ||
|
||
use Okapi\Aop\Tests\ClassLoaderMockTrait; | ||
use Okapi\Aop\Tests\Functional\AdviceApplication\AdviceMatchingAbstractMethod\Aspect\FileUploaderAspect; | ||
use Okapi\Aop\Tests\Functional\AdviceApplication\AdviceMatchingAbstractMethod\Target\LocalFileUploader; | ||
use Okapi\Aop\Tests\Util; | ||
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
#[RunTestsInSeparateProcesses] | ||
class AdviceMatchingAbstractMethodTest extends TestCase | ||
{ | ||
use ClassLoaderMockTrait; | ||
|
||
/** | ||
* @see FileUploaderAspect::modifyResult() | ||
*/ | ||
public function testAbstractMethod(): void | ||
{ | ||
Util::clearCache(); | ||
Kernel::init(); | ||
|
||
$this->assertWillBeWoven(LocalFileUploader::class); | ||
|
||
$uploader = new LocalFileUploader(); | ||
|
||
$result = $uploader->upload('C:\Windows\Temp\file.txt'); | ||
|
||
/** @noinspection PhpConditionAlreadyCheckedInspection */ | ||
$this->assertEquals( | ||
'C:/Windows/Temp/file.txt', | ||
$result | ||
); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...tractMethod/Aspect/FileUploaderAspect.php → ...tractMethod/Aspect/FileUploaderAspect.php
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
16 changes: 16 additions & 0 deletions
16
tests/Functional/AdviceApplication/AdviceMatchingAbstractMethod/Kernel.php
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,16 @@ | ||
<?php | ||
|
||
namespace Okapi\Aop\Tests\Functional\AdviceApplication\AdviceMatchingAbstractMethod; | ||
|
||
use Okapi\Aop\AopKernel; | ||
use Okapi\Aop\Tests\Functional\AdviceApplication\AdviceMatchingAbstractMethod\Aspect\FileUploaderAspect; | ||
use Okapi\Aop\Tests\Util; | ||
|
||
class Kernel extends AopKernel | ||
{ | ||
protected ?string $cacheDir = Util::CACHE_DIR; | ||
|
||
protected array $aspects = [ | ||
FileUploaderAspect::class, | ||
]; | ||
} |
2 changes: 1 addition & 1 deletion
2
...ethod/ClassesToIntercept/FileUploader.php → ...ingAbstractMethod/Target/FileUploader.php
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
Oops, something went wrong.