|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Component\Translation\Tests\Provider; |
| 13 | + |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | +use Symfony\Component\Translation\Provider\ProviderInterface; |
| 16 | +use Symfony\Component\Translation\Provider\TranslationProviderCollection; |
| 17 | + |
| 18 | +class TranslationProviderCollectionTest extends TestCase |
| 19 | +{ |
| 20 | + public function testKeys() |
| 21 | + { |
| 22 | + $this->assertSame(['foo', 'baz'], $this->createProviderCollection()->keys()); |
| 23 | + } |
| 24 | + |
| 25 | + public function testKeysWithGenerator() |
| 26 | + { |
| 27 | + $this->assertSame(['foo', 'baz'], (new TranslationProviderCollection( |
| 28 | + (function () { |
| 29 | + yield 'foo' => $this->createMock(ProviderInterface::class); |
| 30 | + |
| 31 | + yield 'baz' => $this->createMock(ProviderInterface::class); |
| 32 | + })() |
| 33 | + ))->keys()); |
| 34 | + } |
| 35 | + |
| 36 | + public function testToString() |
| 37 | + { |
| 38 | + $this->assertSame('[foo,baz]', (string) $this->createProviderCollection()); |
| 39 | + } |
| 40 | + |
| 41 | + public function testHas() |
| 42 | + { |
| 43 | + $this->assertTrue($this->createProviderCollection()->has('foo')); |
| 44 | + } |
| 45 | + |
| 46 | + public function testGet() |
| 47 | + { |
| 48 | + $provider = $this->createMock(ProviderInterface::class); |
| 49 | + |
| 50 | + $this->assertSame($provider, (new TranslationProviderCollection([ |
| 51 | + 'foo' => $provider, |
| 52 | + 'baz' => $this->createMock(ProviderInterface::class), |
| 53 | + ]))->get('foo')); |
| 54 | + } |
| 55 | + |
| 56 | + public function testGetThrowsException() |
| 57 | + { |
| 58 | + $this->expectException(\InvalidArgumentException::class); |
| 59 | + $this->expectExceptionMessage('Provider "invalid" not found. Available: "[foo,baz]".'); |
| 60 | + |
| 61 | + $this->createProviderCollection()->get('invalid'); |
| 62 | + } |
| 63 | + |
| 64 | + private function createProviderCollection(): TranslationProviderCollection |
| 65 | + { |
| 66 | + return new TranslationProviderCollection([ |
| 67 | + 'foo' => $this->createMock(ProviderInterface::class), |
| 68 | + 'baz' => $this->createMock(ProviderInterface::class), |
| 69 | + ]); |
| 70 | + } |
| 71 | +} |
0 commit comments