I already tried installing PHPUnit, so I will try simple samples.
message.php
class Message { private $message; public function __construct(string $message){ $this->message = $message; } public function get(){ return $this->message; } }
messageTest.php
require_once ('../vendor/autoload.php'); require_once (dirname(__FILE__) .'../src/message.php'); use PHPUnit\Framework\TestCase; class MessageTest extends TestCase{ public function testGet(){ $message = new Message('hello, world'); $this->assertEquals('hello, world', $message->get()); } }
command line
[vagrant@localhost app]$ vendor/bin/phpunit tests
PHP Warning: require_once(../vendor/autoload.php): failed to open stream: No such file or directory in /home/vagrant/local/app/tests/messageTest.php on line 3
PHP Fatal error: require_once(): Failed opening required ‘../vendor/autoload.php’ (include_path=’.:/usr/share/pear:/usr/share/php’) in /home/vagrant/local/app/tests/messageTest.php on line 3
fix
require_once ('./vendor/autoload.php'); require_once ('./src/message.php'); use PHPUnit\Framework\TestCase; class MessageTest extends TestCase{ public function testGet(){ $message = new Message('hello, world'); $this->assertEquals('hello, world', $message->get()); } }
[vagrant@localhost app]$ vendor/bin/phpunit tests
PHPUnit 7.1.4 by Sebastian Bergmann and contributors.
. 1 / 1 (100%)
Time: 35 ms, Memory: 4.00MB
OK (1 test, 1 assertion)
ohhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh^^