Bolt\Tests\Storage\StorageTest::testGetContentObject PHP Метод

testGetContentObject() публичный Метод

We copy the 'Pages' ContentType into a 'Fakes' configuration and test against this, as PHPUnit keeps the mock in the $this->mockObjects private property array and any further calls to the 'Pages' repo will (currently) fail as the Application object is torn down at the end of the test/class.
    public function testGetContentObject()
    {
        $app = $this->getApp();
        $storage = new Storage($app);
        $content = $storage->getContentObject('pages');
        $this->assertInstanceOf('Bolt\\Legacy\\Content', $content);
        // Fake it until we make it… to the end of the test suite.
        $contentType = $app['config']->get('contenttypes/pages');
        $contentType['name'] = 'Fakes';
        $contentType['singular_name'] = 'Fake';
        $contentType['slug'] = 'fakes';
        $contentType['singular_slug'] = 'fake';
        $contentType['tablename'] = 'fakes';
        $app['config']->set('contenttypes/fakes', $contentType);
        $fields = $app['config']->get('contenttypes/fakes/fields');
        $mock = $this->getMockBuilder(Content::class)->setMethods([])->setConstructorArgs([$app])->setMockClassName('Fakes')->getMock();
        $content = $storage->getContentObject(['class' => 'Fakes', 'fields' => $fields]);
        $this->assertInstanceOf('Fakes', $content);
        $this->assertInstanceOf('Bolt\\Legacy\\Content', $content);
        // Test that a class not instanceof Bolt\Legacy\Content fails
        $mock = $this->getMockBuilder(\stdClass::class)->setMethods(null)->setConstructorArgs([])->setMockClassName('Failing')->getMock();
        $this->setExpectedException('Exception', 'Failing does not extend \\Bolt\\Legacy\\Content.');
        $storage->getContentObject(['class' => 'Failing', 'fields' => $fields]);
    }