by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 10:18
    xepozz commented #4366
  • 09:59
    BoShurik commented #4366
  • 09:54
    sebastianbergmann commented #4366
  • 09:45
    xepozz commented #4366
  • 09:41
    theseer commented #87
  • 08:31
    codecov[bot] commented #71
  • 08:27
    codecov[bot] commented #71
  • 08:26
    codecov[bot] commented #71
  • 08:26
    codecov[bot] commented #71
  • 08:26
    codecov[bot] commented #71
  • 08:25
    codecov[bot] commented #71
  • 08:25
    codecov[bot] commented #71
  • 08:25
    b1rdex synchronize #71
  • 08:24
    codecov[bot] commented #71
  • 08:23
    codecov[bot] commented #71
  • 08:23
    codecov[bot] commented #71
  • 08:22
    codecov[bot] commented #71
  • 08:22
    codecov[bot] commented #71
  • 08:22
    b1rdex synchronize #71
  • 08:21
    codecov[bot] commented #71
rspiewak47
@rspiewak47
Well, if I run the debugger under "Listen for XDebug" and then enter the phpUnit command with quotes myself, I hit my breakpoint!
So if I can figure out where to go to force the quotes, I might not have to do it that way. Or, just use a path without spaces...
Oh - it didn't hit my breakpoint, it hit an exception.
rspiewak47
@rspiewak47
Well, back to the drawing board a bit. I think I'll back off the spaces for now, and then try to figure out how to get a unit test working with XDebug.
Ryein Goddard
@Goddard
you could just remove the spaces from the path and it would work right?
rspiewak47
@rspiewak47
Yes, that part worked. But somehow I've munged this up and nothing is working now. I'll have to walk some things back...
Ryein Goddard
@Goddard
I had to look up the word munged haha
Jeramy
@xylesoft
Good day everyone. Has anyone succesfully mocked Memcached with PHPUnit 8.5?
Jeramy
@xylesoft
For anyone who also might have the same issue as described above, the solution I came up with was using Mockery.
Andrea Bergamasco
@vjandrea
Hello, I'm trying to mark some tests as risky in a Symfony 4.3.9 project using the markAsRisky method, but I can't see any "R" in the testcase output. PhpUnit 8.5.1. Any clue?
HenkPoley
@HenkPoley
@vjandrea possible risky tests are automatically disabled, so you need to explicitly mention them or the risky category for them to run ?
Andrea Bergamasco
@vjandrea
@HenkPoley If i write a test with no assertions I can see that it's automatically marked as Risky and the R appears in the testcase output
William Perreault
@jwillp

Hi everyone, I am having an issue that's making me pull my hair out.
I have a mocked object that has a method called executeCommand.

Now in my test I have the following:

$workflow->doSomething(); // This method will call mock::executeCommand with CommandA::class as argument
$workflow->doSomethingElse(); // This method will call mock::executeCommand with CommandB::class argument

How can I assert that when I call doSomething, mock::executeCommand will effectively have an instance of CommmandA as the argument
and when I call doSomethingElse that mock::executeCommand will effectively have an instance of CommandB as argument.

I tried with ->expect($this->at()), but it does not work, and having an index is making the tests brittle.

For now, the only workaround I have is that:

$commandsExecuted = [
    CommandA::class => false,
    CommandB::class => false
];
$mock->method('executeCommand')->willReturnCallback(static function ($command) use (&$commandsExecuted) {
    $commandsExecuted[get_class($command)] = true;
})

$workflow->doSomething();
$this->assertTrue($commandsExecuted[CommandA::class]);

$workflow->doSomething();
$this->assertTrue($commandsExecuted[CommandB::class]);

Is there any other more concise way?

Nicolas Hohm
@nickel715

@jwillp If I got you right, I would do it like that:

$mock->expects($this->exactly(2))
    ->method('executeCommand')
    ->withConsecutive(
        [$this->isInstanceOf(CommandA::class)],
        [$this->isInstanceOf(CommandB::class)]
    );

$workflow->doSomething();
$workflow->doSomethingElse();

I would also consider spliting the test and calling doSomethingElse in the second test. Then you don't need to use withConsecutive

William Perreault
@jwillp
@nickel715 Thank you very much, it worked as expected! I have to test them in a single test, because $workflow is actually a state machine, that I am making sure transitions correctly
Andrea Bergamasco
@vjandrea
Hello there, i'm trying to use a custom HTML result printer for my testdox reports, without success. If i run phpunit --testdox-html var/testdox.html --printer App\Tests\MyTestdoxPrinter I can see the HTML output in the console, and no file is generated. How can I override this and write to the specified file?
Andrea Bergamasco
@vjandrea
I correct myself: a file is generated, but it uses the internal HTML result printer, and not the class I provided with the --printer option
Noel da Costa
@geoidesic
Greetz!
How can I force phpunit v8 to use a specific version of PHP from a particular path?
Noel da Costa
@geoidesic
Or alternately – what determines the $PATH that PHPUnit will use as it seems to be different from my own profile's $PATH... as it is picking up a different version of PHP.
I might be able to track it down myself if someone could point me to where the PHPUnit code calls php?
Noel da Costa
@geoidesic
Ok found a solution... looks like I can call php vendor/bin/phpunit to set the correct version. Thanks for all the help.
Alan Fox
@temppeck

I'm getting a 'Could not connect to the database' error when I try and run phpUnit. Note - there is no database queries in the file being tested. I think its a phpUnit issue. MySql is running and I'm able to connect to the database using Sequel Pro and MAMP.

Has anyone else come across this?

Alan Fox
@temppeck
Screen Shot 2020-03-23 at 14.15.54.png
Alan Fox
@temppeck
Can someone even tell me what 'database' its trying to connect to?
Is it the local mysql? Is it some stand alone DB?
I'm really struggling with this and need help.
Any info or help would be appreciated
Adrien Crivelli
@PowerKiKi
@temppeck phpunit does not use any database at all. If you see some database related error then it is 100% something in your code (or another lib you use). Most likely your phpunit bootstrap file (declared in phpunit.xml.dist) or a setUp method in your tests tries to connect to a database but configuration is missing (because your app is not correctly bootstraped when used by phpunit) and it fails.
Alan Fox
@temppeck
Thanks for the info Adrien thats what I needed to hear. Perhaps one of the other dependancies does. I'll dig deeper
Alex Barker
@kwhat
Good day, I am having a surprisingly complicated issue with PHPUnit ~8.5. I have two projects, vendor/author/projectA and projectB which is a to level src in this instance. Because projectB is an extension of projectA, I wanted to inherit and extend some unit tests from vendor/author/projectA/tests in my top level projectB/tests. Composer made this surprisingly difficult, but I was able to work around getting their autoloader to load test classes out of vendor with additional entri[es]? in my autoload-dev section. Now composer can autoload the classes vendor/author/projectA, however, phpunit is complaining that it cannot find these classes. I am bootstrapping directly to vendor/autoload.php and other classes seem to load just fine, including local project classes and vendor/author/projectA/src classes, but for some reason php unit is still complaining that it cannot find classes from vendor/author/projectA/tests and I am not sure why. Is there an xml setting I am missing?
Alex Barker
@kwhat
ugh, why cant phpunit simply use the composer autoloader. Ive managed to slug along slightly, but no instead of tests not being found, it cannot find classes in the project the subtest is located in. This is exceptionally painful.
I need to explicitly while list these classes so they can be run, but i dont want to in my coverage report.
Oliver Klee
@oliverklee
Dear all, in one of my projects (https://github.com/MyIntervals/emogrifier), we're currently in the process of moving the tools from Composer dependencies to Phive. As part of this, I tried to use PHPUnit via Phive, but Psalm could not find the PHPUnit classes. Also, we're using psalm/plugin-phpunit (which is not included in the Psalm phar). What's the recommended approach for these two problems?
Cyberiaaxis
@Cyberiaaxis
hi
drewblin
@drewblin

I'm getting error "This build of PHPDBG does not support code coverage" when try to run phpunit with coverage with phpdbg. I found in PHAR line which generate this error:

        if (!\function_exists('PHPUnit\\phpdbg_start_oplog')) {
            throw new \PHPUnit\SebastianBergmann\CodeCoverage\RuntimeException('This build of PHPDBG does not support code coverage');
        }

Then i run and get this result:

prompt> ev function_exists('phpdbg_start_oplog');
1

As i undestand, problem is in namespace before phpdbg_start_oplog. So, why phpdbg_start_oplog is prefixed with PHPUnit namespace in PHAR?

Sergei Morozov
@morozov
Hi, there. Is there any info on how I can merge coverage reports obtained from different environments and therefore having different absolute file paths? As far as I can tell, PHPUnit always generates absolute paths in Clover, PHP or HTML reports but e.g. Scrutinizer manages to merge the reports from Travis CI, AppVeyor and ContinuousPHP w/o any additional input.
Sergei Morozov
@morozov
My end goal is to collect --coverage-php reports (they seem to be the fastest to generate) and convert them to a single HTML report via phpcov.
Jonathan Fontes
@gravataLonga
I’ve real dumb question not related to PHPUnit to its core, but more
conceptual question. I like to test reactphp application that I’m creating , it use TCP Connection half duplex communication. Want to test when connection interface receive some input it get correct output.
I don’t know how to pass a fake connection interface to the event loop, in order to test this one. I don’t like to use mocks.
David Busby
@djbusby
I have PHPUnit 8.5.6, and in my test suite I'm showing four directories -- but when I run phpunit, it's giving a warning about a Base_Case not having tests -- but PHPUnit shoudn't even be trying to select this file for testing.
    <testsuites>
        <testsuite name="All">
            <directory>0_Core/</directory>
            <directory>1_Auth/</directory>
            <directory>2_Account/</directory>
            <directory>3_oAuth2/</directory>
        </testsuite>
    </testsuites>
Those directories have files, exist, are run like expected but in the same root with phpunit.xml is also ./Base_Case.php -- which somehow get's picked up and evaluated (and warned on )
Bram Van der Sype
@Brammm

I have this really weird issue with PHPUnit, I've had it for the longest time (starting from v6 I think) but so far, haven't found a solution. I run integration tests with PHPUnit as well. To keep them speedy, I execute all queries in a transaction, which I manage through doctrine/dbal (not sure if that matters).

If I try to debug something with a var_dump(); die; (yes yes I know...), I won't get my output unless I disable the transactions... I still haven't found what causes that.

Bram Van der Sype
@Brammm
It's also not just output, the script simply freezes.
Sebastian Köhler
@ian76g
hi everyone
I can't find a solution to my output "unrecognized option --whitelist" when running phpunit via intellij ide
Sebastian Köhler
@ian76g
C:\xampp\php-5.6.9-Win32-VC11-x64\php.exe -dxdebug.coverage_enable=1 C:.../Temp/ide-phpunit.php --coverage-clover C:...\coverage\trunk@PartnerDataExchange.xml --whitelist C:/.../trunk --bootstrap C:...\bootstrap.php --no-configuration C:...\TestCode
PHPUnit 4.8.19
Sebastian Köhler
@ian76g
I found the problem. Wihtin my IntelliJ IDE I had to fill up the line "use alternative configuration file" and point it to my phpunit.xml - now coverage works on PHP 5.6.9 with xdebug 2.5.5
Ben Ramsey
@ramsey
Did the behavior of assertContains() change between PHPUnit version 8 and 9? We have a number of tests failing after upgrading to version 9 because it appears they assume assertContains() (in version 8) could accept an array as the needle and return true if the haystack array contained all the keys/values of the needle, but in version 9, it fails.
Ben Ramsey
@ramsey
I've answered my own question. It did change. I need to use assertContainsEquals() for the behavior I'm looking for.