Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement getOriginalException #2678

Merged
merged 2 commits into from
Jun 1, 2017
Merged

Implement getOriginalException #2678

merged 2 commits into from
Jun 1, 2017

Conversation

alexbowers
Copy link
Contributor

No description provided.

*/
public function getOriginalException()
{
return $this->originalException;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace found at end of line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this is why you don't use github to edit files. Fixing now.

@alexbowers
Copy link
Contributor Author

@sebastianbergmann I'm not sure what here could have caused those tests to fail, since no regressions should have been introduced with this. Is this a widespread issue, or have I inadvertently done something bad?

@alexbowers
Copy link
Contributor Author

Example usecase:

public function run(TestResult $result = null)
{
    parent::run($result);

    if ($result->errorCount() > 0) {
        /**
         * @var $error PHPUnit_Framework_TestFailure
         */
        foreach ($result->errors() as $error) {
            $exception = $error->thrownException();
            if ($exception->getClassname() == ApiException::class) {
                $exception = $exception->getOriginalException();
                dump($exception->getErrors());
            }
        }
    }
}

This still causes phpunit to fail with the same exceptions, but instead of just saying:

1) Tests\Product\CustomisationsTest::text_customisation
App\Exceptions\ApiException: Failed to pass validation

/var/www/sites/current/api.xxx.com/app/Exceptions/ApiException.php:27
/var/www/sites/current/api.xxx.com/app/Repositories/BaseRepository.php:135
/var/www/sites/current/api.xxx.com/app/Repositories/BaseRepository.php:127
/var/www/sites/current/api.xxx.com/app/Repositories/BaseRepository.php:207
/var/www/sites/current/api.xxx.com/tests/Product/CustomisationsTest.php:37
/var/www/sites/current/api.xxx.com/tests/TestCase.php:22

it now says:

PHPUnit 6.2-ga18fd3b by Sebastian Bergmann and contributors.

E                                                                   1 / 1 (100%)
Illuminate\Support\MessageBag {#167
  #messages: array:1 [
    "internal_additional_information.customisations.0" => array:1 [
      0 => "The internal additional information.customisations.0 field must be a valid customisation."
    ]
  ]
  #format: ":message"
}


Time: 1.81 seconds, Memory: 6.00MB

There was 1 error:

1) Tests\Product\CustomisationsTest::text_customisation
App\Exceptions\ApiException: Failed to pass validation

/var/www/sites/current/api.xxx.com/app/Exceptions/ApiException.php:27
/var/www/sites/current/api.xxx.com/app/Repositories/BaseRepository.php:135
/var/www/sites/current/api.xxx.com/app/Repositories/BaseRepository.php:127
/var/www/sites/current/api.xxx.com/app/Repositories/BaseRepository.php:207
/var/www/sites/current/api.xxx.com/tests/Product/CustomisationsTest.php:37
/var/www/sites/current/api.xxx.com/tests/TestCase.php:22

ERRORS!
Tests: 1, Assertions: 0, Errors: 1.

@alexbowers
Copy link
Contributor Author

@sebastianbergmann Any chance I can get some feedback on this, and why it may have failed the tests?

@sebastianbergmann sebastianbergmann added this to the PHPUnit 6.2 milestone Jun 1, 2017
@sebastianbergmann sebastianbergmann added the type/enhancement A new idea that should be implemented label Jun 1, 2017
@sebastianbergmann sebastianbergmann self-assigned this Jun 1, 2017
@sebastianbergmann sebastianbergmann merged commit e79069e into sebastianbergmann:master Jun 1, 2017
sebastianbergmann added a commit that referenced this pull request Jun 1, 2017
PHPUnit 6.2-ge79069e by Sebastian Bergmann and contributors.

Runtime:       PHP 7.1.5 with Xdebug 2.5.4
Configuration: /usr/local/src/phpunit/phpunit.xml

.............................................................   61 / 1543 (  3%)
.............................................................  122 / 1543 (  7%)
.............................................................  183 / 1543 ( 11%)
.............................................................  244 / 1543 ( 15%)
.............................................................  305 / 1543 ( 19%)
.............................................................  366 / 1543 ( 23%)
.............................................................  427 / 1543 ( 27%)
.............................................................  488 / 1543 ( 31%)
.............................................................  549 / 1543 ( 35%)
.............................................................  610 / 1543 ( 39%)
.............................................................  671 / 1543 ( 43%)
.............................................................  732 / 1543 ( 47%)
.............................................................  793 / 1543 ( 51%)
.............................................................  854 / 1543 ( 55%)
.............................................................  915 / 1543 ( 59%)
.............................................................  976 / 1543 ( 63%)
............................................................. 1037 / 1543 ( 67%)
............................................................. 1098 / 1543 ( 71%)
............................................................. 1159 / 1543 ( 75%)
............................................................. 1220 / 1543 ( 79%)
............................................................. 1281 / 1543 ( 83%)
............................................................. 1342 / 1543 ( 86%)
............................................................. 1403 / 1543 ( 90%)
............................................................. 1464 / 1543 ( 94%)
........................................F.................... 1525 / 1543 ( 98%)
..................                                            1543 / 1543 (100%)

Time: 8.11 seconds, Memory: 14.00MB

There was 1 failure:

1) /usr/local/src/phpunit/tests/Regression/GitHub/1351.phpt
Failed asserting that string matches format description.
--- Expected
+++ Actual
@@ @@
 PHPUnit 6.2-ge79069e by Sebastian Bergmann and contributors.

-F.E.E                                                               5 / 5 (100%)
+F.EFE                                                               5 / 5 (100%)
@@ @@

+/usr/local/src/phpunit/tests/Regression/GitHub/1351/Issue1351Test.php:32
+
 Caused by
 LogicException: Expected exception.
-Caused by

+/usr/local/src/phpunit/tests/Regression/GitHub/1351/Issue1351Test.php:30
+
 2) Issue1351Test::testPhpCoreLanguageException
 PDOException: SQLSTATE[HY000]: General error: 1 no such table: php_wtf

+/usr/local/src/phpunit/tests/Regression/GitHub/1351/Issue1351Test.php:48

 --

-There was 1 failure:
+There were 2 failures:

 1) Issue1351Test::testFailurePre
 Expected failure.
-There were 2 failures:
+Failed asserting that true is false.
+
+/usr/local/src/phpunit/tests/Regression/GitHub/1351/Issue1351Test.php:14
+
+2) Issue1351Test::testExceptionPost
+ChildProcessClass1351 is not loaded.
+Failed asserting that true is false.
+
+/usr/local/src/phpunit/tests/Regression/GitHub/1351/Issue1351Test.php:39
+
 ERRORS!
-Tests: 5, Assertions: 5, Errors: 2, Failures: 1.
+Tests: 5, Assertions: 5, Errors: 2, Failures: 2.

/usr/local/src/phpunit/src/Framework/Constraint/Constraint.php:117
/usr/local/src/phpunit/src/Framework/Constraint/Constraint.php:62
/usr/local/src/phpunit/src/Framework/Assert.php:2116
/usr/local/src/phpunit/src/Framework/Assert.php:1768
/usr/local/src/phpunit/src/Runner/PhptTestCase.php:126
/usr/local/src/phpunit/src/Runner/PhptTestCase.php:204
/usr/local/src/phpunit/src/Framework/TestSuite.php:746
/usr/local/src/phpunit/src/Framework/TestSuite.php:746
/usr/local/src/phpunit/src/TextUI/TestRunner.php:541
/usr/local/src/phpunit/src/TextUI/Command.php:210
/usr/local/src/phpunit/src/TextUI/Command.php:141

FAILURES!
Tests: 1543, Assertions: 2796, Failures: 1.
@sebastianbergmann
Copy link
Owner

@alexbowers Please send a new pull request that fixes the test failure.

@alexbowers
Copy link
Contributor Author

@sebastianbergmann Is there a guide anywhere on how to run the tests locally?

I get the following error:

PHP Fatal error:  Uncaught Error: Class 'PHPUnit\TextUI\Command' not found in /Users/alex/Development/phpunit/phpunit:53
Stack trace:
#0 {main}
  thrown in /Users/alex/Development/phpunit/phpunit on line 53

Fatal error: Uncaught Error: Class 'PHPUnit\TextUI\Command' not found in /Users/alex/Development/phpunit/phpunit:53
Stack trace:
#0 {main}
  thrown in /Users/alex/Development/phpunit/phpunit on line 53

@sebastianbergmann
Copy link
Owner

You need to install PHPUnit's dependencies first. Have a look at https://github.com/sebastianbergmann/phpunit/blob/master/.github/CONTRIBUTING.md#running-phpunits-own-test-suite

@alexbowers
Copy link
Contributor Author

@sebastianbergmann That is the steps I followed, I still get the same error:


➜  Development git clone git://github.com/sebastianbergmann/phpunit.git
Cloning into 'phpunit'...
remote: Counting objects: 68369, done.
remote: Compressing objects: 100% (31/31), done.
remote: Total 68369 (delta 17), reused 25 (delta 9), pack-reused 68329
Receiving objects: 100% (68369/68369), 22.10 MiB | 7.13 MiB/s, done.
Resolving deltas: 100% (42492/42492), done.
➜  Development cd php
cd: no such file or directory: php
➜  Development cd phpunit
➜  phpunit git:(master) composer install
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 27 installs, 0 updates, 0 removals
  - Installing phar-io/version (1.0.1): Loading from cache
  - Installing phar-io/manifest (1.0.1): Loading from cache
  - Installing sebastian/recursion-context (3.0.0): Loading from cache
  - Installing doctrine/instantiator (1.0.5): Loading from cache
  - Installing sebastian/exporter (3.1.0): Loading from cache
  - Installing sebastian/diff (1.4.3): Loading from cache
  - Installing sebastian/comparator (2.0.0): Loading from cache
  - Installing webmozart/assert (1.2.0): Loading from cache
  - Installing phpdocumentor/reflection-common (1.0): Loading from cache
  - Installing phpdocumentor/type-resolver (0.2.1): Loading from cache
  - Installing phpdocumentor/reflection-docblock (3.1.1): Loading from cache
  - Installing phpspec/prophecy (v1.7.0): Loading from cache
  - Installing sebastian/object-reflector (1.1.1): Loading from cache
  - Installing sebastian/object-enumerator (3.0.2): Loading from cache
  - Installing sebastian/resource-operations (1.0.0): Loading from cache
  - Installing theseer/tokenizer (1.1.0): Loading from cache
  - Installing sebastian/version (2.0.1): Loading from cache
  - Installing sebastian/environment (3.0.3): Loading from cache
  - Installing sebastian/code-unit-reverse-lookup (1.0.1): Loading from cache
  - Installing phpunit/php-token-stream (1.4.11): Loading from cache
  - Installing phpunit/php-text-template (1.2.1): Loading from cache
  - Installing phpunit/php-file-iterator (1.4.2): Loading from cache
  - Installing phpunit/php-code-coverage (5.2.1): Loading from cache
  - Installing phpunit/phpunit-mock-objects (4.0.1): Loading from cache
  - Installing myclabs/deep-copy (1.6.1): Loading from cache
  - Installing phpunit/php-timer (1.0.9): Loading from cache
  - Installing sebastian/global-state (2.0.0): Loading from cache
phpunit/php-code-coverage suggests installing ext-xdebug (^2.5.3)
sebastian/global-state suggests installing ext-uopz (*)
Writing lock file
Generating autoload files
➜  phpunit git:(master) ./phpunit
PHP Fatal error:  Uncaught Error: Class 'PHPUnit\TextUI\Command' not found in /Users/alex/Development/phpunit/phpunit:53
Stack trace:
#0 {main}
  thrown in /Users/alex/Development/phpunit/phpunit on line 53

Fatal error: Uncaught Error: Class 'PHPUnit\TextUI\Command' not found in /Users/alex/Development/phpunit/phpunit:53
Stack trace:
#0 {main}
  thrown in /Users/alex/Development/phpunit/phpunit on line 53

@alexbowers
Copy link
Contributor Author

Ah. I have found the cause.

On my machine, I have a folder ~/Development which deals with all of my side project coding stuff. That folder contains a folder called vendor which is from a past project.

The array(__DIR__ . '/../../autoload.php', __DIR__ . '/../vendor/autoload.php', __DIR__ . '/vendor/autoload.php') line finds this folder first, and this causes the issue.

It has the autoload.php, it autoloads it all in, but what it is loading is the incorrect vendor folder.

Is the order of these files here important, or should it not be __DIR__./vendor/autoload.php first?

If this package gets pulled into a different package, then it would not have its own vendor, which will cause it to not be found anyway.

@alexbowers
Copy link
Contributor Author

@sebastianbergmann I have looked, and can't see how the tests are failing.

Is there any chance somebody with more knowledge of phpunits internals could have a look at them?

@alexbowers
Copy link
Contributor Author

@sebastianbergmann Any chance I could get assistance with fixing the issues this had?

@alexbowers
Copy link
Contributor Author

@sebastianbergmann Any chance I could get your assistance on this? Its a useful feature for us, and we have to currently use a fork since I couldn't resolve the issues you experienced.

@KamilKopaczyk
Copy link

Is there anything we can do to implement it?
It would be extremely useful for getting custom data from exceptions in TestListeners.

@denis-chmel
Copy link
Contributor

@sebastianbergmann
Please consider merging improved PR (all tests are passed now): #3012
It's not entirely clear why #2678 was failing Issue1351Test, but just turning $originalException to be private has helped. Well, I guess it's ok from OOP point of view (as long as there is a getter).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement A new idea that should be implemented
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants