Some Notes about Docker + PHPUnit

This is kinda a confusing subject to learn for me, especially when I am not very familiar with docker yet, nor with PHPUnit. Here is my note as I go along the study process.

Source Link:
Official documentation for PhpUnit

Command to install PHPUnit:

composer require --dev phpunit/phpunit ^6

Source Link:
Composing a Test Suite Using XML Configuration:

<phpunit bootstrap="src/autoload.php">
    <testsuite name="money">
      <exclude>some file or directory name</exclude>

Command to run PHPunit test:

./vendor/bin/phpunit --bootstrap vendor/autoload.php tests/testExample
./vendor/bin/phpunit --bootstrap vendor/autoload.php --testsuite msg

Yet, I am still a bit confused about this whole thing.

Run commands through Docker:
Source link:

//Install PhpUnit:
docker run --rm -v $(pwd):/app composer/composer:latest require --dev phpunit/phpunit ^6.0
//Run test suite:
docker run -v $(pwd):/app --rm phpunit/phpunit:latest --bootstrap vendor/autoload.php --testsuite msg

* Note:
(above flags orders don’t matter)
– -rm is a flag of “clean up”.

Access to mysql from a container:

docker exec -t <container_name> mysql -u<username> -p
docker exec -it dockie_db_1 mysql -uroot -p 

PHPUnit mock usage:

use PHPUnit\Framework\TestCase;

function quickTest($obj,$value=665){
	return $obj->increaseOne($value);

class SomeClass{
	public function increaseOne($value){
		return $value + 1;

class testExample extends TestCase {
    public function testSimple() {
	public function testMocks() {

		$someClass = $this->createMock('SomeClass');


		$b = quickTest($someClass);


More info about mock usage: