PHPUnit no longer works after initializing ArrayCollection (Doctrine 2) in Netbeans

I am working on a PHP project and am using PHPUnit and Doctrine 2. I am using the latest version. I wrote a lot of tests to test all classes, functions and behavior. The tests always work. Everything worked fine. Since I am using Doctrine, I followed the best practice tips and initializes the ArrayCollection in the constructor.

public function __construct($username, $eMail, $password1, $password2) {
    $this->quiz = new ArrayCollection();
    $this->sessions = new ArrayCollection();
    $this->setUsername($username);
    $this->setEMail($eMail);
    $this->setPassword('', $password1, $password2);
}

      

Including the ArrayCollection:

use Doctrine\Common\Collections\ArrayCollection;

      

After this point, PHPUnit tests no longer work.

When I comment out the initialization line again, all test runs again. Participants in the quiz and session are private. Usually the application works.

I am new to Doctrine 2 and PHPUnit. I've tried a lot of things so far, as others have said, including test files, etc. But nothing helped. Perhaps I forgot something in the test folder. Between initializing the ArrayCollection step and not initializing, I haven't changed anything in the test folder.

The test looks like this:

namespace Model;

require_once dirname(__FILE__) . '/../../Model/User.php';

/**
 * Test class for User.
 * Generated by PHPUnit on 2012-04-03 at 14:48:39.
 */
class UserTest extends \PHPUnit_Framework_TestCase {

    /**
     * @var User
     */
    protected $user;

    // constructor of the test suite
    function UserTest($name) {
        $this->PHPUnit_TestCase($name);
    }

    /**
     * Sets up the fixture, for example, opens a network connection.
     * This method is called before a test is executed.
     */
    protected function setUp() {
        $username = 'musteruser';
        $eMail = 'must@muster.ch';
        $pw = 'muster.muster';
        $this->user = new User($username, $eMail, $pw, $pw);
    }

    /**
     * Tears down the fixture, for example, closes a network connection.
     * This method is called after a test is executed.
     */
    protected function tearDown() {
        unset($this->user);
    }

      

Right now I have no idea what the problem might be. Maybe someone has already experienced the same or has some idea of ​​what the problem might be.

Thanks for any help.

+3


source to share


2 answers


I found a solution to the problem. I created a file called bootstrap.php with the following content:

// Import the ClassLoader
use Doctrine\Common\ClassLoader;

// Autoloader for Doctrine
require '/../../php/PEAR/Doctrine/Common/ClassLoader.php';

// Autoloading for Doctrine
$doctrineClassLoader = new ClassLoader('Doctrine', realpath(__DIR__ . '/../../php/PEAR'));
$doctrineClassLoader->register();

      



The file is placed in the home directory of test files, part for Unit Testing in the NetBeans project. The important thing is that nothing should be edited in the test cabinets.

0


source


You may need to make sure the Doctrine \ Common folder is in the include path for your test cases when calling PHPUnit.



You are setting up classloaders for your application as you need to do the same for your tests.

0


source







All Articles