Skip to content

Commit

Permalink
Merge pull request PrestaShop#14231 from MathiasReker/test
Browse files Browse the repository at this point in the history
php unit no expectation annotation
  • Loading branch information
PierreRambaud authored and mbadrani committed Jul 18, 2019
2 parents 229130e + 4985878 commit 7ec5488
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 77 deletions.
5 changes: 2 additions & 3 deletions tests-legacy/Unit/Core/Localization/CLDR/CurrencyTest.php
Expand Up @@ -137,11 +137,10 @@ public function testGetSymbols()
);
}

/**
* @expectedException \PrestaShop\PrestaShop\Core\Localization\Exception\LocalizationException
*/
public function testGetSymbolsWithInvalidSymbolType()
{
$this->setExpectedException(LocalizationException::class);

$this->cldrCurrency->getSymbol('foobar');
}
}
17 changes: 9 additions & 8 deletions tests-legacy/Unit/Core/Localization/CLDR/LocaleTest.php
Expand Up @@ -33,6 +33,7 @@
use PrestaShop\PrestaShop\Core\Localization\CLDR\Locale;
use PrestaShop\PrestaShop\Core\Localization\CLDR\LocaleData;
use PrestaShop\PrestaShop\Core\Localization\CLDR\NumberSymbolsData;
use PrestaShop\PrestaShop\Core\Localization\Exception\LocalizationException;

class LocaleTest extends TestCase
{
Expand Down Expand Up @@ -192,11 +193,11 @@ public function testGetNumberSymbolsByNumberingSystem()
* Given a valid CLDR Locale object and an invalid numbering system
* When asking for the number symbols of this system
* Then an exception should be raised
*
* @expectedException \PrestaShop\PrestaShop\Core\Localization\Exception\LocalizationException
*/
public function testGetNumberSymbolsByNumberingSystemWithUnknownNumberingSystem()
{
$this->setExpectedException(LocalizationException::class);

$this->cldrLocale->getNumberSymbolsByNumberingSystem('foobar');
}

Expand All @@ -223,11 +224,11 @@ public function testGetDecimalPattern()
* Given a valid CLDR Locale object and an invalid numbering system
* When asking for decimal pattern of this system
* Then an exception should be raised
*
* @expectedException \PrestaShop\PrestaShop\Core\Localization\Exception\LocalizationException
*/
public function testGetDecimalPatternWithUnknownNumberingSystem()
{
$this->setExpectedException(LocalizationException::class);

$this->cldrLocale->getDecimalPattern('foobar');
}

Expand All @@ -254,11 +255,11 @@ public function testGetPercentPattern()
* Given a valid CLDR Locale object and an invalid numbering system
* When asking for percentage pattern of this system
* Then an exception should be raised
*
* @expectedException \PrestaShop\PrestaShop\Core\Localization\Exception\LocalizationException
*/
public function testGetPercentPatternWithUnknownNumberingSystem()
{
$this->setExpectedException(LocalizationException::class);

$this->cldrLocale->getPercentPattern('foobar');
}

Expand All @@ -285,11 +286,11 @@ public function testGetCurrencyPattern()
* Given a valid CLDR Locale object and an invalid numbering system
* When asking for currency (price formatting) pattern of this system
* Then an exception should be raised
*
* @expectedException \PrestaShop\PrestaShop\Core\Localization\Exception\LocalizationException
*/
public function testGetCurrencyPatternWithUnknownNumberingSystem()
{
$this->setExpectedException(LocalizationException::class);

$this->cldrLocale->getCurrencyPattern('foobar');
}

Expand Down
9 changes: 5 additions & 4 deletions tests-legacy/Unit/Core/Localization/Currency/CurrencyTest.php
Expand Up @@ -28,6 +28,7 @@

use PHPUnit\Framework\TestCase;
use PrestaShop\PrestaShop\Core\Localization\Currency;
use PrestaShop\PrestaShop\Core\Localization\Exception\LocalizationException;

class CurrencyTest extends TestCase
{
Expand Down Expand Up @@ -130,11 +131,11 @@ public function testGetSymbol()
* Given a valid Currency instance and un unknown or invalid locale code
* When requesting the currency symbol for the said locale code
* Then an exception should be raised
*
* @expectedException \PrestaShop\PrestaShop\Core\Localization\Exception\LocalizationException
*/
public function testGetSymbolWithUnknownLocaleCode()
{
$this->setExpectedException(LocalizationException::class);

$this->currency->getSymbol('foobar');
}

Expand Down Expand Up @@ -172,11 +173,11 @@ public function testGetName()
* Given a valid Currency instance and an invalid or unknown locale code
* When requesting the currency name for the said locale code
* Then an exception should be raised
*
* @expectedException \PrestaShop\PrestaShop\Core\Localization\Exception\LocalizationException
*/
public function testGetNameWithUnknownLocaleCode()
{
$this->setExpectedException(LocalizationException::class);

$this->currency->getName('foobar');
}
}
Expand Up @@ -146,11 +146,11 @@ public function provideValidCurrencyCodes()
* Given an unknown or invalid currency code
* When asking the currency repository for the corresponding Currency
* Then an exception should be raised
*
* @expectedException \PrestaShop\PrestaShop\Core\Localization\Exception\LocalizationException
*/
public function testGetCurrencyWithUnknownCode()
{
$this->setExpectedException(LocalizationException::class);

$this->currencyRepository->getCurrency('foo', 'bar');
}
}
9 changes: 5 additions & 4 deletions tests-legacy/Unit/Core/Localization/Locale/LocaleTest.php
Expand Up @@ -34,6 +34,7 @@
use PrestaShop\PrestaShop\Core\Localization\Specification\NumberCollection;
use PrestaShop\PrestaShop\Core\Localization\Specification\NumberSymbolList;
use PrestaShop\PrestaShop\Core\Localization\Specification\Price as PriceSpecification;
use PrestaShop\PrestaShop\Core\Localization\Exception\LocalizationException;

class LocaleTest extends TestCase
{
Expand Down Expand Up @@ -126,11 +127,11 @@ public function testFormatNumber($number, $expected)
* Then an exception should be raised
*
* For more formatting cases, @see \Tests\Unit\Core\Localization\Number\FormatterTest
*
* @expectedException \PrestaShop\PrestaShop\Core\Localization\Exception\LocalizationException
*/
public function testFormatNumberWithInvalidRawNumber()
{
$this->setExpectedException(LocalizationException::class);

$this->cldrLocale->formatNumber('foobar');
}

Expand Down Expand Up @@ -210,11 +211,11 @@ public function provideValidPriceData()
* Potentially invalid currency
*
* @dataProvider provideInvalidPriceData
*
* @expectedException \PrestaShop\PrestaShop\Core\Localization\Exception\LocalizationException
*/
public function testFormatNumberWithInvalidPriceData($number, $currency)
{
$this->setExpectedException(LocalizationException::class);

$this->cldrLocale->formatPrice($number, $currency);
}

Expand Down
11 changes: 5 additions & 6 deletions tests/Integration/Adapter/ContainerBuilderTest.php
Expand Up @@ -33,6 +33,7 @@
use PrestaShop\Module\Banner\Repository\FrontRepository;
use PrestaShop\PrestaShop\Adapter\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;

class ContainerBuilderTest extends TestCase
{
Expand Down Expand Up @@ -98,20 +99,18 @@ public function testAdminModuleServices()
$this->assertInstanceOf(AdminRepository::class, $adminRepository);
}

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
*/
public function testNoAdminServicesInFront()
{
$this->setExpectedException(ServiceNotFoundException::class);

$container = ContainerBuilder::getContainer('front', true);
$container->get('ps_banner.admin_repository');
}

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
*/
public function testNoFrontServicesInAdmin()
{
$this->setExpectedException(ServiceNotFoundException::class);

$container = ContainerBuilder::getContainer('admin', true);
$container->get('ps_banner.front_repository');
}
Expand Down
Expand Up @@ -32,6 +32,7 @@
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Console\Exception\RuntimeException;

class GenerateMailTemplatesCommandTest extends KernelTestCase
{
Expand All @@ -45,12 +46,10 @@ public function setUp()
self::bootKernel();
}

/**
* @expectedException \Symfony\Component\Console\Exception\RuntimeException
* @expectedExceptionMessage Not enough arguments (missing: "theme, locale").
*/
public function testMissingArguments()
{
$this->setExpectedException(RuntimeException::class, 'Not enough arguments (missing: "theme, locale").');

$application = new Application(static::$kernel);

$command = $application->find('prestashop:mail:generate');
Expand Down
Expand Up @@ -36,6 +36,7 @@
use PrestaShop\PrestaShop\Core\MailTemplate\MailTemplateRendererInterface;
use PrestaShop\PrestaShop\Core\MailTemplate\Transformation\TransformationCollectionInterface;
use PrestaShop\PrestaShop\Core\MailTemplate\Transformation\TransformationInterface;
use PrestaShop\PrestaShop\Core\Exception\FileNotFoundException;
use Symfony\Component\Templating\EngineInterface;

class MailTemplateTwigRendererTest extends TestCase
Expand All @@ -61,11 +62,10 @@ public function testConstructor()
$this->assertNotNull($generator);
}

/**
* @expectedException \PrestaShop\PrestaShop\Core\Exception\FileNotFoundException
*/
public function testFileNotFound()
{
$this->setExpectedException(FileNotFoundException::class);

$templatePaths = [
MailTemplateInterface::HTML_TYPE => 'path/to/non_existent_template.html.twig',
];
Expand Down
55 changes: 19 additions & 36 deletions tests/Unit/Core/Data/AbstractTypedCollectionTest.php
Expand Up @@ -28,6 +28,7 @@

use PHPUnit\Framework\TestCase;
use PrestaShop\PrestaShop\Core\Data\AbstractTypedCollection;
use PrestaShop\PrestaShop\Core\Exception\TypeException;

class AbstractTypedCollectionTest extends TestCase
{
Expand All @@ -45,23 +46,19 @@ public function testConstructor()
$this->assertCount(2, $collection);
}

/**
* @expectedException \PrestaShop\PrestaShop\Core\Exception\TypeException
* @expectedExceptionMessage Invalid element type Tests\Unit\Core\Data\InvalidCollectionTestElement, expected Tests\Unit\Core\Data\CollectionTestElement
*/
public function testInvalidConstructor()
{
$this->setExpectedException(TypeException::class, 'Invalid element type Tests\Unit\Core\Data\InvalidCollectionTestElement, expected Tests\Unit\Core\Data\CollectionTestElement');

new TestCollection([
new InvalidCollectionTestElement(),
]);
}

/**
* @expectedException \PrestaShop\PrestaShop\Core\Exception\TypeException
* @expectedExceptionMessage Invalid element type Tests\Unit\Core\Data\InvalidCollectionTestElement, expected Tests\Unit\Core\Data\CollectionTestElement
*/
public function testPartialInvalidConstructor()
{
$this->setExpectedException(TypeException::class, 'Invalid element type Tests\Unit\Core\Data\InvalidCollectionTestElement, expected Tests\Unit\Core\Data\CollectionTestElement');

new TestCollection([
new CollectionTestElement(),
new InvalidCollectionTestElement(),
Expand All @@ -84,12 +81,10 @@ public function testRemoveElement()
$this->assertFalse($elementRemoved);
}

/**
* @expectedException \PrestaShop\PrestaShop\Core\Exception\TypeException
* @expectedExceptionMessage Invalid element type Tests\Unit\Core\Data\InvalidCollectionTestElement, expected Tests\Unit\Core\Data\CollectionTestElement
*/
public function testInvalidRemoveElement()
{
$this->setExpectedException(TypeException::class, 'Invalid element type Tests\Unit\Core\Data\InvalidCollectionTestElement, expected Tests\Unit\Core\Data\CollectionTestElement');

$element = new CollectionTestElement();
$collection = new TestCollection([$element]);
$this->assertNotNull($collection);
Expand All @@ -112,12 +107,10 @@ public function testOffsetSet()
$this->assertEquals($element, $collection->offsetGet(1));
}

/**
* @expectedException \PrestaShop\PrestaShop\Core\Exception\TypeException
* @expectedExceptionMessage Invalid element type Tests\Unit\Core\Data\InvalidCollectionTestElement, expected Tests\Unit\Core\Data\CollectionTestElement
*/
public function testInvalidOffsetSet()
{
$this->setExpectedException(TypeException::class, 'Invalid element type Tests\Unit\Core\Data\InvalidCollectionTestElement, expected Tests\Unit\Core\Data\CollectionTestElement');

$collection = new TestCollection();
$this->assertNotNull($collection);
$this->assertCount(0, $collection);
Expand All @@ -138,12 +131,10 @@ public function testContains()
$this->assertTrue($collection->contains($element));
}

/**
* @expectedException \PrestaShop\PrestaShop\Core\Exception\TypeException
* @expectedExceptionMessage Invalid element type Tests\Unit\Core\Data\InvalidCollectionTestElement, expected Tests\Unit\Core\Data\CollectionTestElement
*/
public function testInvalidContains()
{
$this->setExpectedException(TypeException::class, 'Invalid element type Tests\Unit\Core\Data\InvalidCollectionTestElement, expected Tests\Unit\Core\Data\CollectionTestElement');

$collection = new TestCollection();
$this->assertNotNull($collection);
$this->assertCount(0, $collection);
Expand Down Expand Up @@ -172,12 +163,10 @@ public function testIndexOf()
$this->assertEquals('element', $collection->indexOf($element));
}

/**
* @expectedException \PrestaShop\PrestaShop\Core\Exception\TypeException
* @expectedExceptionMessage Invalid element type Tests\Unit\Core\Data\InvalidCollectionTestElement, expected Tests\Unit\Core\Data\CollectionTestElement
*/
public function testInvalidIndexOf()
{
$this->setExpectedException(TypeException::class, 'Invalid element type Tests\Unit\Core\Data\InvalidCollectionTestElement, expected Tests\Unit\Core\Data\CollectionTestElement');

$collection = new TestCollection();
$this->assertNotNull($collection);
$this->assertCount(0, $collection);
Expand All @@ -199,12 +188,10 @@ public function testSet()
$this->assertEquals($element, $collection['element']);
}

/**
* @expectedException \PrestaShop\PrestaShop\Core\Exception\TypeException
* @expectedExceptionMessage Invalid element type Tests\Unit\Core\Data\InvalidCollectionTestElement, expected Tests\Unit\Core\Data\CollectionTestElement
*/
public function testInvalidSet()
{
$this->setExpectedException(TypeException::class, 'Invalid element type Tests\Unit\Core\Data\InvalidCollectionTestElement, expected Tests\Unit\Core\Data\CollectionTestElement');

$collection = new TestCollection();
$this->assertNotNull($collection);
$this->assertCount(0, $collection);
Expand All @@ -225,12 +212,10 @@ public function testAdd()
$this->assertEquals($element, $collection[0]);
}

/**
* @expectedException \PrestaShop\PrestaShop\Core\Exception\TypeException
* @expectedExceptionMessage Invalid element type Tests\Unit\Core\Data\InvalidCollectionTestElement, expected Tests\Unit\Core\Data\CollectionTestElement
*/
public function testInvalidAdd()
{
$this->setExpectedException(TypeException::class, 'Invalid element type Tests\Unit\Core\Data\InvalidCollectionTestElement, expected Tests\Unit\Core\Data\CollectionTestElement');

$collection = new TestCollection();
$this->assertNotNull($collection);
$this->assertCount(0, $collection);
Expand All @@ -255,12 +240,10 @@ public function testAddMock()
$this->assertEquals($elementMock, $collection[0]);
}

/**
* @expectedException \PrestaShop\PrestaShop\Core\Exception\TypeException
* @expectedExceptionMessage Invalid element type string, expected Tests\Unit\Core\Data\CollectionTestElement
*/
public function testInvalidString()
{
$this->setExpectedException(TypeException::class, 'Invalid element type string, expected Tests\Unit\Core\Data\CollectionTestElement');

$collection = new TestCollection();
$this->assertNotNull($collection);
$this->assertCount(0, $collection);
Expand Down

0 comments on commit 7ec5488

Please sign in to comment.