approvals / ApprovalTests.php

Apache License 2.0
26 stars 7 forks source link

[Bug?]: Parse error #1

Open JacquesDurand opened 2 years ago

JacquesDurand commented 2 years ago

Hi ! I recently stumbled upon Approval testing and am very glad some people made a library for it in php, thank you for that !

I am currently trying (for a class project) to upgrade a legacy application ( php 5.6, symfony 3.1) which contains a few controllers and wanted to setup approval tests before trying to upgrade/refacto the existing code base.

I ended up with the following error while trying to setup a simple test (your given example actually):

Parse error: syntax error, unexpected ':', expecting ';' or '{' in .../vendor/approvals/approval-tests/src/Namers/PHPUnitNamer.php on line 71

My Test Case is the following:

<?php

namespace Tests\Approvals\Controller;

use ApprovalTests\Approvals;
use PHPUnit\Framework\TestCase;

class DefaultControllerTest extends TestCase
{
    public function testList()
    {
        $list = ['zero', 'one', 'two', 'three', 'four', 'five'];
        Approvals::verifyList($list);
    }

//    public function testIndex()
//    {
//        $client = static::createClient();
//
//        $crawler = $client->request('GET', '/');
//
//        $response = (array) $client->getResponse();
//        Approvals::verifyAsJson($response);
//    }

}

And even the simple testList() returns the error mentioned earlier. If it is any help, I am working through docker with a custom image of php-fpm-5.6-alpine, phpunit is at 5.7 version.

Thanks in advance and if you need any more details I would happily provide !

vansari commented 1 year ago

Hi @JacquesDurand

it seems that the return type of __toString is the reason of your issue. I opened a MR which can easily "fix" this problem. BTW: Why do you work with PHP 5.6 in 2022?

https://github.com/approvals/ApprovalTests.php/pull/3

JacquesDurand commented 1 year ago

Hi @vansari , thank you for responding and taking the time to have a look ! I actually do not work with PHP 5.6 on a day to day basis (and I am glad I don't have to), it was the specific goal of a school project to upgrade an old application to a more recent version ;)

ilyaguy commented 1 year ago

BTW: Why do you work with PHP 5.6 in 2022?

Now it is 2023, but project is on PHP 5.6. It is without any tests, so I want to cover it with tests, then upgrade at least to 7.x. :)