I have written phpunit test. I ran it by using following commands:
C:\Program Files (x86)\Ampps\www\phpunit.dev\vendor\bin>phpunit -c ../../phpunit.xml
But end up having this error:
PHP Fatal error: Class 'Acme\SumFinder' not found in C:\Program Files (x86)\Ampps\www\phpunit.dev\tests\AcmeTests\SumFinderTest.php on line 15
I have tried several solutions from these questions:
- Class 'sample\question2\Hello' not found with composer and phpunit
- Autoloading classes in PHPUnit using Composer and autoload.php
but nothing works. What could be the problem and how am I going to solve it? Thanks!
My directory structures:
- phpunit.dev/src/Acme/SumFinder.php
- phpunit.dev/tests/AcmeTests/SumFinderTest.php
- phpunit.dev/composer.json
- phpunit.dev/phpunit.xml
My composer.json written like this:
{
"require-dev": {
"phpunit/phpunit": "3.7.*"
},
"autoload": {
"psr-4": {
"Acme\\": "./src/"
}
},
"autoload-dev": {
"psr-4": {
"AcmeTests\\": "./tests/"
}
}
}
My Acme\SumFinder.php written like this:
<?php
namespace Acme;
class SumFinder {
private $inputArray;
function __construct($inputArray = null) { ... }
function findSum() { ... }
function compareArrays() { ... }
}
?>
My AcmeTests\SumFinderTest.php:
<?php
namespace AcmeTests;
use Acme\SumFinder;
class SumFinderTest extends \PHPUnit_Framework_TestCase
function testFindSum() { ... }
function testCompareArrays() { ... }
?>
My phpunit.xml config file:
<?xml version="1.0" encoding="utf-8" ?>
<phpunit colors="true" bootstrap="./vendor/autoload.php">
<testsuites>
<testsuite name="First Test">
<directory>./tests</directory>
</testsuite>
</testsuites>
I am using windows 10 and AMPPS stack if it could help solve my problem.