-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
519 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
/* | ||
* Merge autoload-dev and require-dev from one composer.json | ||
* | ||
* This is used to install the module within a Magento 2 installation, but with its dev dependencies | ||
*/ | ||
declare(strict_types=1); | ||
|
||
$fromFile = $argv[1]; | ||
$toFile = $argv[2]; | ||
|
||
$fromJson = json_decode(file_get_contents($fromFile), true); | ||
$toJson = json_decode(file_get_contents($toFile), true); | ||
var_dump($fromJson, $toJson, json_last_error_msg()); | ||
|
||
foreach ($fromJson['autoload-dev']['psr-4'] ?? [] as $key => $value) { | ||
$pathPrefix = dirname($fromFile) . DIRECTORY_SEPARATOR; | ||
$fromJson['autoload-dev']['psr-4'][$key] = $pathPrefix . $value; | ||
} | ||
|
||
$toJson['require-dev'] = array_replace_recursive($toJson['require-dev'] ?? [], $fromJson['require-dev']); | ||
$toJson['autoload-dev'] = array_merge_recursive($toJson['autoload-dev'] ?? [], $fromJson['autoload-dev']); | ||
|
||
echo json_encode($toJson, JSON_PRETTY_PRINT); |
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,37 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace IntegerNet\AsyncVarnish\Api; | ||
|
||
interface TagRepositoryInterface | ||
{ | ||
/** | ||
* Insert multiple Tags | ||
* | ||
* @param string[] $tags | ||
* @return int | ||
* @throws \Exception | ||
*/ | ||
public function insertMultiple(array $tags = []): int; | ||
|
||
/** | ||
* Delete multiple Tags by max entity_id | ||
* | ||
* @param int $maxId | ||
* @return int | ||
* @throws \Exception | ||
*/ | ||
public function deleteUpToId(int $maxId = 0): int; | ||
|
||
/** | ||
* @throws \Zend_Db_Statement_Exception | ||
*/ | ||
public function getAll(): array; | ||
|
||
/** | ||
* Return last ID (after getAll() call) | ||
* | ||
* @return int | ||
*/ | ||
public function getLastUsedId(): int; | ||
} |
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,78 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace IntegerNet\AsyncVarnish\Test\Integration; | ||
|
||
use IntegerNet\AsyncVarnish\Api\TagRepositoryInterface; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
abstract class AbstractTagRepositoryTest extends TestCase | ||
{ | ||
/** | ||
* @var TagRepositoryInterface | ||
*/ | ||
protected $tagRepository; | ||
|
||
protected function setUp() | ||
{ | ||
$this->tagRepository = $this->getTestSubject(); | ||
} | ||
|
||
abstract protected function getTestSubject(): TagRepositoryInterface; | ||
|
||
public function testInsertAndRetrieve() | ||
{ | ||
$affected = $this->tagRepository->insertMultiple(['x', 'y', 'z']); | ||
$this->assertEquals(3, $affected, 'insertMultiple() should return number of inserted rows'); | ||
$this->assertEqualsCanonicalizing(['x', 'y', 'z'], $this->tagRepository->getAll()); | ||
} | ||
|
||
public function testNoDuplicatesAreRetrieved() | ||
{ | ||
$affected = $this->tagRepository->insertMultiple(['x', 'y', 'x']); | ||
$this->assertEquals(3, $affected, 'insertMultiple() should return number of inserted rows'); | ||
$this->assertEqualsCanonicalizing(['x', 'y'], $this->tagRepository->getAll()); | ||
} | ||
|
||
public function testNoDuplicatesAreRetrievedAfterSubsequentCalls() | ||
{ | ||
$affected = $this->tagRepository->insertMultiple(['x', 'y']); | ||
$this->assertEquals(2, $affected, 'insertMultiple() should return number of inserted rows'); | ||
$affected = $this->tagRepository->insertMultiple(['y', 'z']); | ||
$this->assertEquals(2, $affected, 'insertMultiple() should return number of inserted rows'); | ||
$this->assertEqualsCanonicalizing(['x', 'y', 'z'], $this->tagRepository->getAll()); | ||
} | ||
|
||
public function testLastUsedIdIncreases() | ||
{ | ||
$this->tagRepository->insertMultiple(['x']); | ||
$this->tagRepository->getAll(); | ||
$lastUsedId = $this->tagRepository->getLastUsedId(); | ||
$this->tagRepository->insertMultiple(['y']); | ||
$this->tagRepository->getAll(); | ||
//TODO maybe throw exception if getAll has not been called before: | ||
$this->assertEquals($lastUsedId + 1, $this->tagRepository->getLastUsedId()); | ||
} | ||
|
||
public function testDeleteUpToId() | ||
{ | ||
$this->tagRepository->insertMultiple(['x', 'y', 'z']); | ||
$this->tagRepository->getAll(); | ||
$lastUsedId = $this->tagRepository->getLastUsedId(); | ||
$this->tagRepository->insertMultiple(['a', 'b', 'c']); | ||
$affected = $this->tagRepository->deleteUpToId($lastUsedId); | ||
$this->assertEquals(3, $affected, 'deleteUpToId() should return number of deleted rows'); | ||
$this->assertEqualsCanonicalizing(['a', 'b', 'c'], $this->tagRepository->getAll()); | ||
} | ||
|
||
/** | ||
* Backport from PHPUnit 8 | ||
* | ||
* @param array $expected | ||
* @param array $actual | ||
*/ | ||
public static function assertEqualsCanonicalizing(array $expected, array $actual, string $message = '') | ||
{ | ||
self::assertEquals($expected, $actual, $message, 0.0, 10, true); | ||
} | ||
} |
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 | ||
declare(strict_types=1); | ||
|
||
namespace IntegerNet\AsyncVarnish\Test\Integration; | ||
|
||
use Magento\Framework\Component\ComponentRegistrar; | ||
use Magento\Framework\Module\ModuleList; | ||
use Magento\TestFramework\ObjectManager; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ModuleTest extends TestCase | ||
{ | ||
|
||
/** | ||
* @var ObjectManager | ||
*/ | ||
private $objectManager; | ||
const MODULE_NAME = 'IntegerNet_AsyncVarnish'; | ||
/** | ||
* @return ModuleList | ||
*/ | ||
private function getTestModuleList() | ||
{ | ||
/** @var ModuleList $moduleList */ | ||
$moduleList = $this->objectManager->create(ModuleList::class); | ||
return $moduleList; | ||
} | ||
protected function setUp() | ||
{ | ||
$this->objectManager = ObjectManager::getInstance(); | ||
} | ||
public function testTheModuleIsRegistered() | ||
{ | ||
$registrar = new ComponentRegistrar(); | ||
$paths = $registrar->getPaths(ComponentRegistrar::MODULE); | ||
$this->assertArrayHasKey(self::MODULE_NAME, $paths, 'Module should be registered'); | ||
} | ||
public function testTheModuleIsKnownAndEnabled() | ||
{ | ||
$moduleList = $this->getTestModuleList(); | ||
$this->assertTrue($moduleList->has(self::MODULE_NAME), 'Module should be enabled'); | ||
} | ||
|
||
} |
Oops, something went wrong.