/** * @test * @covers SlimApp\Db\DbTable::setConfig * @covers SlimApp\Db\DbTable::getConfig * @uses SlimApp\HasRequiredParamsTrait */ public function setConfig_sets_config_and_returns_DbTable_instance_if_config_containing_all_required_params() { $table = $this->getMockForAbstractClass('SlimApp\\Db\\DbTable'); $dbTable = new \SebastianBergmann\PeekAndPoke\Proxy($table); $dbTable->setRequiredParams(['driver', 'host', 'charset', 'dbname', 'username', 'password']); $config = ['driver' => 'whatever', 'host' => 'whatever', 'charset' => 'whatever', 'dbname' => 'whatever', 'username' => 'whatever', 'password' => 'whatever']; $result = $dbTable->setConfig($config); $this->assertEquals(new \ArrayObject($config, \ArrayObject::ARRAY_AS_PROPS), $dbTable->getConfig()); $this->assertInstanceOf('\\SlimApp\\Db\\DbTable', $result); }
/** * @test * @covers SlimApp\HasRequiredParamsTrait::hasRequiredParams * @param array $requiredParams The required parameters * @param array $data The data to be checked * @param boolean $returnValue The value returned by hasRequiredParams() * @dataProvider provider_hasRequiredParams_returns_true_if_data_contains_required_parameters * @see https://sandro-keil.de/blog/2015/08/31/phpunit-with-peek-and-poke-no-more-reflection/ */ function hasRequiredParams_returns_true_if_data_contains_required_parameters(array $requiredParams, array $data, $returnValue) { // Get mock for our trait $trait = $this->getMockForTrait('\\SlimApp\\HasRequiredParamsTrait'); // Proxy the protected properties and methods $hasRequiredParamsTrait = new \SebastianBergmann\PeekAndPoke\Proxy($trait); // Now we can set the protected params... $hasRequiredParamsTrait->setRequiredParams($requiredParams); // ... and run the protected method $result = $hasRequiredParamsTrait->hasRequiredParams($data); $this->assertEquals($returnValue, $result); }