objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class) ->getMockForAbstractClass(); $this->environmentMock = $this->getMockBuilder(Environment::class) ->disableOriginalConstructor() ->getMock(); $this->model = new PlaceholderFactory( $this->objectManagerMock, [ PlaceholderFactory::TYPE_ENVIRONMENT => Environment::class, 'wrongClass' => \stdClass::class, ] ); } public function testCreate() { $this->objectManagerMock->expects($this->once()) ->method('create') ->with(Environment::class) ->willReturn($this->environmentMock); $this->assertInstanceOf( Environment::class, $this->model->create(PlaceholderFactory::TYPE_ENVIRONMENT) ); } /** * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage There is no defined type dummyClass */ public function testCreateNonExisted() { $this->model->create('dummyClass'); } /** * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage Object is not instance of Magento\Config\Model\Placeholder\PlaceholderInterface */ public function testCreateWrongImplementation() { $this->model->create('wrongClass'); } }