Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
Fix phpunit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wbloszyk authored and jordisala1991 committed Jun 30, 2020
1 parent 5c5506f commit 72a3789
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 8 deletions.
2 changes: 1 addition & 1 deletion tests/BasketBundle/Resources/XliffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Sonata\BasketBundle\Tests\Resources;

use Sonata\CoreBundle\Test\XliffValidatorTestCase;
use Sonata\Component\Tests\Test\XliffValidatorTestCase;

class XliffTest extends XliffValidatorTestCase
{
Expand Down
84 changes: 84 additions & 0 deletions tests/Component/Test/XliffValidatorTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\Component\Tests\Test;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Translation\Exception\InvalidResourceException;
use Symfony\Component\Translation\Loader\XliffFileLoader;

abstract class XliffValidatorTestCase extends TestCase
{
/**
* @var XliffFileLoader
*/
protected $loader;

/**
* @var string[]
*/
protected $errors = [];

protected function setUp(): void
{
$this->loader = new XliffFileLoader();
}

/**
* @dataProvider getXliffPaths
*/
public function testXliff($path)
{
$this->validatePath($path);

if (\count($this->errors) > 0) {
$this->fail(sprintf('Unable to parse xliff files: %s', implode(', ', $this->errors)));
}

$this->assertCount(
0,
$this->errors,
sprintf('Unable to parse xliff files: %s', implode(', ', $this->errors))
);
}

/**
* @return array List all path to validate xliff
*/
abstract public function getXliffPaths();

/**
* @param string $file The path to the xliff file
*/
protected function validateXliff($file)
{
try {
$this->loader->load($file, 'en');
$this->assertTrue(true, sprintf('Successful loading file: %s', $file));
} catch (InvalidResourceException $e) {
$this->errors[] = sprintf('%s => %s', $file, $e->getMessage());
}
}

/**
* @param string $path The path to lookup for Xliff file
*/
protected function validatePath($path)
{
$files = glob(sprintf('%s/*.xliff', $path));

foreach ($files as $file) {
$this->validateXliff($file);
}
}
}
2 changes: 1 addition & 1 deletion tests/CustomerBundle/Resources/XliffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Sonata\CustomerBundle\Tests\Resources;

use Sonata\CoreBundle\Test\XliffValidatorTestCase;
use Sonata\Component\Tests\Test\XliffValidatorTestCase;

class XliffTest extends XliffValidatorTestCase
{
Expand Down
2 changes: 1 addition & 1 deletion tests/DeliveryBundle/Resources/XliffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Sonata\DeliveryBundle\Tests\Resources;

use Sonata\CoreBundle\Test\XliffValidatorTestCase;
use Sonata\Component\Tests\Test\XliffValidatorTestCase;

class XliffTest extends XliffValidatorTestCase
{
Expand Down
2 changes: 1 addition & 1 deletion tests/InvoiceBundle/Resources/XliffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Sonata\InvoiceBundle\Tests\Resources;

use Sonata\CoreBundle\Test\XliffValidatorTestCase;
use Sonata\Component\Tests\Test\XliffValidatorTestCase;

class XliffTest extends XliffValidatorTestCase
{
Expand Down
2 changes: 1 addition & 1 deletion tests/OrderBundle/Resources/XliffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Sonata\OrderBundle\Tests\Resources;

use Sonata\CoreBundle\Test\XliffValidatorTestCase;
use Sonata\Component\Tests\Test\XliffValidatorTestCase;

class XliffTest extends XliffValidatorTestCase
{
Expand Down
2 changes: 1 addition & 1 deletion tests/PaymentBundle/Resources/XliffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Sonata\PaymentBundle\Tests\Resources;

use Sonata\CoreBundle\Test\XliffValidatorTestCase;
use Sonata\Component\Tests\Test\XliffValidatorTestCase;

class XliffTest extends XliffValidatorTestCase
{
Expand Down
2 changes: 1 addition & 1 deletion tests/PriceBundle/Resources/XliffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Sonata\PriceBundle\Tests\Resources;

use Sonata\CoreBundle\Test\XliffValidatorTestCase;
use Sonata\Component\Tests\Test\XliffValidatorTestCase;

class XliffTest extends XliffValidatorTestCase
{
Expand Down
2 changes: 1 addition & 1 deletion tests/ProductBundle/Resources/XliffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Sonata\ProductBundle\Tests\Resources;

use Sonata\CoreBundle\Test\XliffValidatorTestCase;
use Sonata\Component\Tests\Test\XliffValidatorTestCase;

class XliffTest extends XliffValidatorTestCase
{
Expand Down

0 comments on commit 72a3789

Please sign in to comment.