class ZfExtensionManagerSfContainerTest

Same name in this branch
  1. 9 core/tests/Drupal/Tests/Component/Bridge/ZfExtensionManagerSfContainerTest.php \Drupal\Tests\Component\Bridge\ZfExtensionManagerSfContainerTest
Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Component/Bridge/ZfExtensionManagerSfContainerTest.php \Drupal\Tests\Component\Bridge\ZfExtensionManagerSfContainerTest

@coversDefaultClass \Drupal\aggregator\ZfExtensionManagerSfContainer @group aggregator @group legacy

Hierarchy

Expanded class hierarchy of ZfExtensionManagerSfContainerTest

File

core/modules/aggregator/tests/src/Unit/ZfExtensionManagerSfContainerTest.php, line 17

Namespace

Drupal\Tests\aggregator\Unit
View source
class ZfExtensionManagerSfContainerTest extends UnitTestCase {
    
    /**
     * @covers ::setContainer
     * @covers ::setStandalone
     * @covers ::get
     */
    public function testGet() {
        $service = new \stdClass();
        $service->value = 'my_value';
        $container = new ContainerBuilder();
        $container->set('foo', $service);
        $bridge = new ZfExtensionManagerSfContainer();
        $bridge->setContainer($container);
        $this->assertEquals($service, $bridge->get('foo'));
        $bridge->setStandalone(StandaloneExtensionManager::class);
        $this->assertInstanceOf(Entry::class, $bridge->get('Atom\\Entry'));
        // Ensure that the standalone service is checked before the container.
        $container->set('atomentry', $service);
        $this->assertInstanceOf(Entry::class, $bridge->get('Atom\\Entry'));
    }
    
    /**
     * @covers ::setContainer
     * @covers ::setStandalone
     * @covers ::has
     */
    public function testHas() {
        $service = new \stdClass();
        $service->value = 'my_value';
        $container = new ContainerBuilder();
        $container->set('foo', $service);
        $bridge = new ZfExtensionManagerSfContainer();
        $bridge->setContainer($container);
        $this->assertTrue($bridge->has('foo'));
        $this->assertFalse($bridge->has('bar'));
        $this->assertFalse($bridge->has('Atom\\Entry'));
        $bridge->setStandalone(StandaloneExtensionManager::class);
        $this->assertTrue($bridge->has('Atom\\Entry'));
    }
    
    /**
     * @covers ::setStandalone
     */
    public function testSetStandaloneException() {
        $this->expectException(\RuntimeException::class);
        $this->expectExceptionMessage('Drupal\\Tests\\aggregator\\Unit\\ZfExtensionManagerSfContainerTest must implement Laminas\\Feed\\Reader\\ExtensionManagerInterface or Laminas\\Feed\\Writer\\ExtensionManagerInterface');
        $bridge = new ZfExtensionManagerSfContainer();
        $bridge->setStandalone(static::class);
    }
    
    /**
     * @covers ::get
     */
    public function testGetContainerException() {
        $this->expectException(ServiceNotFoundException::class);
        $this->expectExceptionMessage('You have requested a non-existent service "test.foo".');
        $container = new ContainerBuilder();
        $bridge = new ZfExtensionManagerSfContainer('test.');
        $bridge->setContainer($container);
        $bridge->setStandalone(StandaloneExtensionManager::class);
        $bridge->get('foo');
    }
    
    /**
     * @covers ::__construct
     * @covers ::has
     * @covers ::get
     */
    public function testPrefix() {
        $service = new \stdClass();
        $service->value = 'my_value';
        $container = new ContainerBuilder();
        $container->set('foo.bar', $service);
        $bridge = new ZfExtensionManagerSfContainer('foo.');
        $bridge->setContainer($container);
        $this->assertTrue($bridge->has('bar'));
        $this->assertFalse($bridge->has('baz'));
        $this->assertEquals($service, $bridge->get('bar'));
    }
    
    /**
     * @covers ::canonicalizeName
     * @dataProvider canonicalizeNameProvider
     */
    public function testCanonicalizeName($name, $canonical_name) {
        $service = new \stdClass();
        $service->value = 'my_value';
        $container = new ContainerBuilder();
        $container->set($canonical_name, $service);
        $bridge = new ZfExtensionManagerSfContainer();
        $bridge->setContainer($container);
        $this->assertTrue($bridge->has($name));
        $this->assertEquals($service, $bridge->get($name));
    }
    
    /**
     * Data provider for testReverseProxyEnabled.
     *
     * Replacements:
     *   array('-' => '', '_' => '', ' ' => '', '\\' => '', '/' => '')
     */
    public function canonicalizeNameProvider() {
        return [
            [
                'foobar',
                'foobar',
            ],
            [
                'foo-bar',
                'foobar',
            ],
            [
                'foo_bar',
                'foobar',
            ],
            [
                'foo bar',
                'foobar',
            ],
            [
                'foo\\bar',
                'foobar',
            ],
            [
                'foo/bar',
                'foobar',
            ],
            // There is also a strtolower in canonicalizeName.
[
                'Foo/bAr',
                'foobar',
            ],
            [
                'foo/-_\\ bar',
                'foobar',
            ],
        ];
    }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overrides
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals Deprecated protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 338
UnitTestCase::setUpBeforeClass public static function
ZfExtensionManagerSfContainerTest::canonicalizeNameProvider public function Data provider for testReverseProxyEnabled.
ZfExtensionManagerSfContainerTest::testCanonicalizeName public function @covers ::canonicalizeName
@dataProvider canonicalizeNameProvider
ZfExtensionManagerSfContainerTest::testGet public function @covers ::setContainer
@covers ::setStandalone
@covers ::get
ZfExtensionManagerSfContainerTest::testGetContainerException public function @covers ::get
ZfExtensionManagerSfContainerTest::testHas public function @covers ::setContainer
@covers ::setStandalone
@covers ::has
ZfExtensionManagerSfContainerTest::testPrefix public function @covers ::__construct
@covers ::has
@covers ::get
ZfExtensionManagerSfContainerTest::testSetStandaloneException public function @covers ::setStandalone

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.