Upgrading phpunit v5.1 to V6.5

Asked

Viewed 19 times

0

Hello, I am upgrading phpunit from a 5.1 to 6.5 system, but from the upgrade, the tests that were all working successfully started to fail.

The error message is:

1) Tests Administration Controller Alunocontrollertest::testModuloController Typeerror: Argument 3 passed to Sebastianbergmann Globalstate Snapshot::__Construct() must be of the type Boolean, null Given, called in /usr/share/php/Phpunit/Framework/Testcase.php on line 2177

I searched for documentation for the migration but couldn’t find it. Can someone who has been through it help me? Or know of any document to perform the migration?

The code file of the test in question is:

<?php

namespace Tests\Administracao\Controller;

use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase;
use PHPUnit\Framework\TestCase;
use Domain\Model\Instituicao\Instituicao;
use Domain\Model\Usuario\Administrador;
use Domain\Model\Usuario\Email;
use Domain\Model\Usuario\Senha;


/**
 * Classe com métodos comuns para todos os controllers da api
 */
abstract class AbstractControllerTest extends TestCase
{   
    private $instituicao;

    public function setUp()
    {
        $this->setApplicationConfig(include './config/application.config.php');
        parent::setUp();

        $serviceManager = $this->getApplicationServiceLocator();

        $this->instituicao = $serviceManager->get('InstituicaoRepository')->getByUrl('uov');
    }

    public function auth()
    {
        // simula o repositório para não fazer modificações no banco
        $session = $this->getMock('Session', array('offsetGet', 'offsetUnset'));

        $usuario = $this->novoUsuario();

        $session->expects($this->any())
                ->method('offsetGet')
                ->willReturn($usuario);

        $serviceManager = $this->getApplicationServiceLocator();
        $serviceManager->setAllowOverride(true);
        $serviceManager->setService('Session', $session);
    }

    /**
     * Cria um novo usuário
     */
    private function novoUsuario()
    {
        $email = new Email('[email protected]');
        $senha = new Senha('123456');       
        $usuario = new Administrador('Teste', $email, $senha, $this->instituicao);
        return $usuario;
    }
}

And also:

<?php

namespace Tests\Administracao\Controller;

use Doctrine\ORM\Tools\Pagination\Paginator;

/**
 * Testa os métodos do controller do Aluno
 */
class AlunoControllerTest extends AbstractControllerTest
{
    public function testModuloController()
    {
        $this->dispatch('/uov/alunos');
        $this->assertModuleName('Administracao');
        $this->assertControllerName('Administracao\Controller\AlunoController');
        $this->assertControllerClass('AlunoController');
        $this->assertMatchedRouteName('instituicao/alunos');
    }
}

1 answer

0

I found that it is compatibility problem between my version of Zendframework(2.2.) and the new version of phpunit(6.5.). So I had to keep the old one.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.