-
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.
[MetricsPower] Added unit and feature tests
- Loading branch information
1 parent
8467a10
commit e10599b
Showing
15 changed files
with
140 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[apcu] | ||
zend_extension=apcu.so | ||
|
||
apc.enabled=1 |
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 was deleted.
Oops, something went wrong.
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
75 changes: 75 additions & 0 deletions
75
Tests/Feature/Factory/PrometheusStorageAdapterFactoryTest.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,75 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* | ||
* Copyright (c) 2024 Mykhailo Shtanko fractalzombie@gmail.com | ||
* | ||
* For the full copyright and license information, please view the LICENSE.MD | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FRZB\Component\MetricsPower\Tests\Feature\Factory; | ||
|
||
use FRZB\Component\MetricsPower\Enum\StorageType; | ||
use FRZB\Component\MetricsPower\Factory\Exception\NotSupportedStorageAdapterException; | ||
use FRZB\Component\MetricsPower\Factory\PrometheusStorageAdapterFactoryInterface; | ||
use Prometheus\Storage\APC; | ||
use Prometheus\Storage\APCng; | ||
use Prometheus\Storage\InMemory; | ||
use Prometheus\Storage\Redis; | ||
use Prometheus\Storage\RedisNg; | ||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
|
||
uses(KernelTestCase::class); | ||
|
||
beforeEach(function (): void { | ||
$this->ensureKernelShutdown(); | ||
$this->bootKernel(); | ||
}); | ||
|
||
test('It can create needed storage adapter', function (StorageType $storage): void { | ||
$factory = $this->getContainer()->get(PrometheusStorageAdapterFactoryInterface::class); | ||
|
||
$storageAdapter = $factory->createStorageAdapter(['storage' => $storage->value, 'redis' => []]); | ||
|
||
expect($storageAdapter)->toBeInstanceOf( | ||
match ($storage) { | ||
StorageType::Redis => Redis::class, | ||
StorageType::RedisNg => RedisNg::class, | ||
StorageType::InMemory => InMemory::class, | ||
default => throw new \InvalidArgumentException('Unexpected match value'), | ||
} | ||
); | ||
})->with([ | ||
StorageType::Redis, | ||
StorageType::RedisNg, | ||
StorageType::InMemory, | ||
]); | ||
|
||
test('It can create apcu, apcu-ng storage adapter', function (StorageType $storage): void { | ||
$factory = $this->getContainer()->get(PrometheusStorageAdapterFactoryInterface::class); | ||
|
||
$storageAdapter = $factory->createStorageAdapter(['storage' => $storage->value, 'redis' => []]); | ||
|
||
expect($storageAdapter)->toBeInstanceOf( | ||
match ($storage) { | ||
StorageType::Apc => APC::class, | ||
StorageType::ApcNg => APCng::class, | ||
default => throw new \InvalidArgumentException('Unexpected match value'), | ||
} | ||
); | ||
})->with([ | ||
StorageType::Apc, | ||
StorageType::ApcNg, | ||
])->skip(!\extension_loaded('apcu') || !apcu_enabled()); | ||
|
||
test('It can not create unknown storage adapter', function (): void { | ||
$factory = $this->getContainer()->get(PrometheusStorageAdapterFactoryInterface::class); | ||
|
||
$factory->createStorageAdapter(['storage' => 'unknown-storage']); | ||
})->throws(NotSupportedStorageAdapterException::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
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 |
---|---|---|
@@ -1,9 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* | ||
* Copyright (c) 2024 Mykhailo Shtanko fractalzombie@gmail.com | ||
* | ||
* For the full copyright and license information, please view the LICENSE.MD | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FRZB\Component\MetricsPower\Tests\Unit\Traits; | ||
|
||
use FRZB\Component\MetricsPower\Tests\Stub\Enum\TestEnum; | ||
|
||
test('It can map values from enum', function () { | ||
test('It can map values from enum', function (): void { | ||
expect(TestEnum::values())->toBe(['one', 'two']); | ||
}); |