-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature #228 Add an ability to define your own Inflector for Metadata…
… class (pamil) This PR was merged into the 1.7-dev branch. Discussion ---------- See Sylius/Sylius#11440 for more details. Commits ------- ece9536 Add an ability to define your own Inflector for Metadata class
- Loading branch information
Showing
6 changed files
with
96 additions
and
19 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 |
---|---|---|
|
@@ -5,3 +5,5 @@ | |
|
||
/composer.phar | ||
/composer.lock | ||
|
||
/.phpunit.result.cache |
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,61 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Paweł Jędrzejewski | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\Component\Resource\Tests\Metadata; | ||
|
||
use Doctrine\Inflector\InflectorFactory; | ||
use Doctrine\Inflector\Rules\Patterns; | ||
use Doctrine\Inflector\Rules\Ruleset; | ||
use Doctrine\Inflector\Rules\Substitution; | ||
use Doctrine\Inflector\Rules\Substitutions; | ||
use Doctrine\Inflector\Rules\Transformations; | ||
use Doctrine\Inflector\Rules\Word; | ||
use PHPUnit\Framework\Assert; | ||
use PHPUnit\Framework\TestCase; | ||
use Sylius\Component\Resource\Metadata\Metadata; | ||
|
||
/** | ||
* @psalm-suppress PropertyNotSetInConstructor Having some issues with custom PHPUnit annotations | ||
*/ | ||
final class MetadataTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
* @runInSeparateProcess | ||
* @preserveGlobalState disabled | ||
*/ | ||
public function it_uses_a_custom_inflector(): void | ||
{ | ||
$factory = InflectorFactory::create(); | ||
$factory->withPluralRules(new Ruleset( | ||
new Transformations(), | ||
new Patterns(), | ||
new Substitutions(new Substitution(new Word('taxon'), new Word('taxons'))) | ||
)); | ||
$inflector = $factory->build(); | ||
|
||
Metadata::setInflector($inflector); | ||
|
||
$metadata = Metadata::fromAliasAndConfiguration('app.taxon', ['driver' => 'whatever']); | ||
|
||
Assert::assertSame('taxons', $metadata->getPluralName()); | ||
} | ||
|
||
/** @test */ | ||
public function it_uses_a_default_inflector(): void | ||
{ | ||
$metadata = Metadata::fromAliasAndConfiguration('app.taxon', ['driver' => 'whatever']); | ||
|
||
Assert::assertSame('taxa', $metadata->getPluralName()); | ||
} | ||
} |
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,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.4/phpunit.xsd" | ||
colors="true" | ||
> | ||
<testsuites> | ||
<testsuite name="SyliusResource Test Suite"> | ||
<directory>./Tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |