PHP code example of adgoal / phpunit-entity-tester
1. Go to this page and download the library: Download adgoal/phpunit-entity-tester library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
adgoal / phpunit-entity-tester example snippets
namespace Demo\Tests;
use PhpUnitEntityTester\AccessorTester;
use PhpUnitEntityTester\AccessorCollectionTester;
class MyEntityTest extends \PHPUnit\Framework\TestCase
{
public function simpleTest()
{
$entity = new MyEntity(); // The entity that you want to test
// Test 'setName' and 'getName'
new AccessorTester($entity, 'name')->test('John Doe');
// Test 'addFruit', 'removeFruit' and 'getFruits'
new AccessorCollectionTester($entity, 'fruits')->test('apple', 'pear');
}
}
use PhpUnitEntityTester\AccessorTester;
$tester = new AccessortTester($entity, 'attribute');
/**
* @dataProvider providerTestAccessor
*/
public function testAccessor($attribute, $setValue, $getValue = AccessorTester::USE_SET_DATA)
{
$entity = new YourEntityClass();
$tester = new AccessorTester($entity, $attribute);
$tester->test($setValue, $getValue);
}
public function providerTestAccessor()
{
return [
['name', 'John Doe'],
['surname', 'JD'],
['astro', 'lion'],
['age', 12],
['age', -5, 0],
['color', 'red', '#ff0000'],
['createdAt', '2015-12-01', new \Datetime('2015-12-01')],
// ...
// one line here, generate complete test of your accessor
];
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.