expectException(InvalidArgumentException::class); new RdsTaskLogBroker(''); } public function testGetPersistenceWhenInstantiatingANewOneThenItReturnsOneWithTheRequiredInterface() { $commonPersistenceSqlPersistenceMock = $this->getMockBuilder(\common_persistence_SqlPersistence::class)->disableOriginalConstructor()->getMock(); $commonPersistenceManagerMock = $this->getMockBuilder(\common_persistence_Manager::class)->getMock(); $commonPersistenceManagerMock->expects($this->once()) ->method('getPersistenceById') ->willReturn($commonPersistenceSqlPersistenceMock); $serviceManagerMock = $this->getMockBuilder(ServiceManager::class) ->disableOriginalConstructor() ->setMethods(['get']) ->getMock(); $serviceManagerMock->expects($this->once()) ->method('get') ->willReturn($commonPersistenceManagerMock); $rdsLogBrokerMock = $this->getMockBuilder(RdsTaskLogBroker::class) ->disableOriginalConstructor() ->setMethods(['getServiceLocator']) ->getMock(); $rdsLogBrokerMock->expects($this->once()) ->method('getServiceLocator') ->willReturn($serviceManagerMock); $persistenceCaller = function () { return $this->getPersistence(); }; // Bind the closure to $rdsLogBrokerMock's scope. // $bound is now a Closure, and calling it is like asking $rdsLogBrokerMock to call $this->getPersistence(); and return the results. $bound = $persistenceCaller->bindTo($rdsLogBrokerMock, $rdsLogBrokerMock); $this->assertInstanceOf(\common_persistence_SqlPersistence::class, $bound()); } public function testGetTableNameWhenContainerNameIsSuppliedByOptionThenItShouldBeInTheTableName() { $prefix = 'tq'; $containerName = 'example_container_name'; $broker = new RdsTaskLogBroker('fakePersistence', $containerName); $tableNameCaller = function () { return $this->getTableName(); }; $bound = $tableNameCaller->bindTo($broker, $broker); $this->assertEquals($prefix . '_' . $containerName, $bound()); } public function testGetTableNameWhenContainerNameIsNotSuppliedByOptionThenTableNameShouldHaveADefaultValue() { $prefix = 'tq'; $defaultName = 'task_log'; $broker = new RdsTaskLogBroker('fakePersistence'); $tableNameCaller = function () { return $this->getTableName(); }; $bound = $tableNameCaller->bindTo($broker, $broker); $this->assertEquals($prefix . '_' . $defaultName, $bound()); } }