create the file: composer.json
{
"require-dev": {
"mockery/mockery": "dev-master",
"phpunit/phpunit": "6.4"
}
}
run: composer install
create the test file MockeryTest.php inside the test folder:
<?php
//Filename: MockeryTest.php
use PHPUnit\Framework\TestCase;
class MockeryTest extends TestCase {
protected function tearDown() {
\Mockery::close();
}
function testMockeryWorks() {
$mock = \Mockery::mock('AClassToBeMocked');
$mock->shouldReceive('someMethod')->once();
$workerObject = new AClassToWorkWith;
$workerObject->doSomethingWit($mock);
}
}
class AClassToBeMocked {}
class AClassToWorkWith {
function doSomethingWit($anotherClass) {
return $anotherClass->someMethod();
}
}
You can list the available tests:
./vendor/bin/phpunit --color --list-tests test
Now you can run the test:
./vendor/bin/phpunit --color test