add php unit test

This commit is contained in:
patryk
2022-08-22 14:57:43 +02:00
parent 616eeea3c0
commit 342a913c26
9 changed files with 222 additions and 2 deletions

View File

@@ -198,3 +198,7 @@ jobs:
name: Behat logs
path: etc/build/
if-no-files-found: ignore
-
name: Run PHPUnit
run: vendor/bin/phpunit --colors=always

View File

@@ -42,7 +42,8 @@
"symfony/web-profiler-bundle": "^4.4 || ^5.2",
"vimeo/psalm": "4.7.1",
"bitbag/coding-standard": "^1.0.1",
"polishsymfonycommunity/symfony-mocker-container": "^1.0"
"polishsymfonycommunity/symfony-mocker-container": "^1.0",
"lchrusciel/api-test-case": "^5.2"
},
"conflict": {
"symfony/form": "4.4.11 || 4.4.12"
@@ -50,7 +51,8 @@
"autoload": {
"psr-4": {
"BitBag\\SyliusElasticsearchPlugin\\": "src/",
"Tests\\BitBag\\SyliusElasticsearchPlugin\\Application\\": "tests/Application"
"Tests\\BitBag\\SyliusElasticsearchPlugin\\Application\\": "tests/Application",
"Tests\\BitBag\\SyliusElasticsearchPlugin\\Integration\\": "tests/PHPUnit/Integration"
}
},
"autoload-dev": {

24
phpunit.xml Normal file
View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/8.5/phpunit.xsd"
colors="true"
bootstrap="tests/Application/config/bootstrap.php">
<testsuites>
<testsuite name="BitBag SyliusElesticsearchPlugin Test Suite">
<directory>tests/PHPUnit</directory>
</testsuite>
</testsuites>
<php>
<ini name="error_reporting" value="-1" />
<server name="KERNEL_CLASS_PATH" value="/tests/Application/Kernel.php" />
<server name="IS_DOCTRINE_ORM_SUPPORTED" value="true"/>
<server name="KERNEL_CLASS" value="Tests\BitBag\SyliusElasticsearchPlugin\Application\Kernel"/>
<server name="EXPECTED_RESPONSES_DIR" value="tests\Responses\json"/>
<env name="APP_ENV" value="test"/>
<env name="SHELL_VERBOSITY" value="-1" />
</php>
</phpunit>

View File

@@ -58,4 +58,6 @@ return [
Sylius\Bundle\ApiBundle\SyliusApiBundle::class => ['all' => true],
SyliusLabs\DoctrineMigrationsExtraBundle\SyliusLabsDoctrineMigrationsExtraBundle::class => ['all' => true],
Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true],
Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle::class => ['test' => true],
Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle::class => ['test' => true],
];

View File

@@ -0,0 +1,9 @@
Sylius\Component\Product\Model\ProductAttribute:
product_attribute_brand:
code: 't_shirt_brand'
type: 'text'
storage_type: 'text'
position: 1
translatable: 0

View File

@@ -0,0 +1,63 @@
Sylius\Component\Core\Model\Channel:
channel_web:
code: 'WEB'
name: 'Web Channel'
hostname: 'localhost'
description: 'Lorem ipsum'
baseCurrency: '@currency_usd'
defaultLocale: '@locale_en'
locales: ['@locale_en']
color: 'black'
enabled: true
taxCalculationStrategy: 'order_items_based'
Sylius\Component\Currency\Model\Currency:
currency_usd:
code: 'USD'
Sylius\Component\Locale\Model\Locale:
locale_en:
code: 'en_US'
Sylius\Component\Core\Model\Product:
product_mug:
code: 'MUG'
channels: ['@channel_web']
currentLocale: 'en_US'
translations:
en_US: '@product_translation_mug'
Sylius\Component\Core\Model\ProductTranslation:
product_translation_mug:
slug: 'mug'
locale: 'en_US'
name: 'Mug'
description: '<paragraph(2)>'
translatable: '@product_mug'
Sylius\Component\Product\Model\ProductAttribute:
product_attribute_brand:
code: 't_shirt_brand'
type: 'text'
storage_type: 'text'
position: 1
translatable: 0
Sylius\Component\Product\Model\ProductAttributeValue:
product_attribute_value_brand:
product: '@product_mug'
attribute: '@product_attribute_brand'
locale_code: '@locale_en'
value: 'You are breathtaking'
Sylius\Component\Core\Model\Taxon:
mugs:
code: "mugs"
Sylius\Component\Core\Model\ProductTaxon:
productTaxon1:
product: "@product_mug"
taxon: "@mugs"
position: 0

View File

@@ -0,0 +1,33 @@
<?php
/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
declare(strict_types=1);
namespace Tests\BitBag\SyliusElasticsearchPlugin\Integration;
use ApiTestCase\JsonApiTestCase;
abstract class IntegrationTestCase extends JsonApiTestCase
{
public function __construct(?string $name = null, array $data = [], string $dataName = '')
{
parent::__construct($name, $data, $dataName);
$this->dataFixturesPath = __DIR__ . '/DataFixtures/ORM';
}
protected function setUp(): void
{
}
protected function tearDown(): void
{
}
}

View File

@@ -0,0 +1,39 @@
<?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace Tests\BitBag\SyliusElasticsearchPlugin\Integration\Repository;
use BitBag\SyliusElasticsearchPlugin\Repository\ProductAttributeRepository;
use Tests\BitBag\SyliusElasticsearchPlugin\Integration\IntegrationTestCase;
class ProductAttributeRepositoryTest extends IntegrationTestCase
{
/** @var ProductAttributeRepository */
private $attributeRepository;
public function SetUp(): void
{
parent::SetUp();
$this->attributeRepository = self::$container->get('bitbag.sylius_elasticsearch_plugin.repository.product_attribute_repository');
}
public function test_get_attribute_type_by_name(): void
{
$this->loadFixturesFromFiles(['Repository/ProductAttributeValueRepositoryTest/test_product_attribute_repository.yaml']);
$result = $this->attributeRepository->getAttributeTypeByName('t_shirt_brand');
$this->assertNotEmpty($result);
$this->assertIsString($result);
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace Tests\BitBag\SyliusElasticsearchPlugin\Integration\Repository;
use ApiTestCase\JsonApiTestCase;
use BitBag\SyliusElasticsearchPlugin\Repository\ProductAttributeValueRepository;
use BitBag\SyliusElasticsearchPlugin\Repository\TaxonRepository;
use Sylius\Bundle\CoreBundle\Doctrine\ORM\AttributeRepository;
use Tests\BitBag\SyliusElasticsearchPlugin\Integration\IntegrationTestCase;
class ProductAttributeValueRepositoryTest extends IntegrationTestCase
{
/** @var ProductAttributeValueRepository */
private $productAttributeValueRepository;
/** @var AttributeRepository */
private $attributeRepository;
/** @var TaxonRepository */
private $taxonRepository;
public function SetUp(): void
{
parent::SetUp();
$this->productAttributeValueRepository = self::$container->get('bitbag.sylius_elasticsearch_plugin.repository.product_attribute_value_repository');
$this->attributeRepository = self::$container->get('sylius.repository.product_attribute');
$this->taxonRepository = self::$container->get('sylius.repository.taxon');
}
public function test_get_unique_attribute_values(): void
{
$this->loadFixturesFromFiles(['Repository/ProductAttributeValueRepositoryTest/test_product_attribute_value_repository.yaml']);
$attribute = $this->attributeRepository->findAll()[0];
$taxon = $this->taxonRepository->findAll()[0];
$result = $this->productAttributeValueRepository->getUniqueAttributeValues($attribute, $taxon);
$this->assertNotEmpty($result);
$this->assertEquals(1, \count($result));
}
}