Skip to content

Commit

Permalink
[Tests] Added test coverage for Message and Plural Value Objects
Browse files Browse the repository at this point in the history
  • Loading branch information
alongosz committed Apr 24, 2024
1 parent 078b53e commit 624e04c
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 0 deletions.
61 changes: 61 additions & 0 deletions tests/lib/Repository/Values/Translation/MessageTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Tests\Core\Repository\Values\Translation;

use Ibexa\Contracts\Core\Repository\Values\Translation\Message;
use PHPUnit\Framework\TestCase;

/**
* @covers \Ibexa\Contracts\Core\Repository\Values\Translation\Message
*/
final class MessageTest extends TestCase
{
/**
* @dataProvider getDataForTestStringable
*/
public function testStringable(Message $message, string $expectedString): void
{
self::assertSame($expectedString, (string)$message);
}

/**
* @return array<string, array{\Ibexa\Contracts\Core\Repository\Values\Translation\Message, string}>
*/
public static function getDataForTestStringable(): iterable
{
yield 'message with substitution values' => [
new Message(
'Anna has some oranges in %object%',
[
'%object%' => 'a basket',
]
),
'Anna has some oranges in a basket',
];

yield 'message with multiple substitution values' => [
new Message(
'%first_name% has some data in %storage_type%',
[
'%first_name%' => 'Anna',
'%storage_type%' => 'her database',
]
),
'Anna has some data in her database',
];

yield 'message with no substitution values' => [
new Message(
'This value is not correct',
[]
),
'This value is not correct',
];
}
}
63 changes: 63 additions & 0 deletions tests/lib/Repository/Values/Translation/PluralTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Tests\Core\Repository\Values\Translation;

use Ibexa\Contracts\Core\Repository\Values\Translation\Plural;
use PHPUnit\Framework\TestCase;

/**
* @covers \Ibexa\Contracts\Core\Repository\Values\Translation\Plural
*/
final class PluralTest extends TestCase
{
/**
* @dataProvider getDataForTestStringable
*/
public function testStringable(Plural $message, string $expectedString): void
{
self::assertSame($expectedString, (string)$message);
}

/**
* @return array<string, array{\Ibexa\Contracts\Core\Repository\Values\Translation\Plural, string}>
*/
public static function getDataForTestStringable(): iterable
{
yield 'singular form' => [
new Plural(
'John has %apple_count% apple',
'John has %apple_count% apples',
[
'%apple_count%' => 1,
]
),
'John has 1 apple',
];

yield 'plural form' => [
new Plural(
'John has %apple_count% apple',
'John has %apple_count% apples',
[
'%apple_count%' => 2,
]
),
'John has 2 apples',
];

yield 'no substitution values' => [
new Plural(
'John has some apples',
'John has a lot of apples',
[]
),
'John has a lot of apples',
];
}
}

0 comments on commit 624e04c

Please sign in to comment.