Git Product home page Git Product logo

Comments (4)

jails avatar jails commented on June 2, 2024 1

Is it actually expected behavior?

Well, as you can see, PHP prefixes error messages with the "callable context" for throwed TypeError, so "Kahlan\Cli\Kahlan::{closure}():" is something added by PHP itself.

<?php
namespace Simple\Test;
use DateTime;
use Throwable;

function test(DateTime $datetime) {}

try {
    test(null);
} catch (Throwable $e) {
    echo $e->getMessage(); // Simple\Test\test(): Argument #1 ($datetime) must be of type DateTime, null given, called in [...][...] on line 11
}

I'd expect the test should give me something like this if the test was failed.

Indeed, I fixed it in the 5.1.1 release.

from kahlan.

jails avatar jails commented on June 2, 2024

When you define a specific error message to an Exception it must matches the throwed one.
What make you feel there's an issue here ?

from kahlan.

feryardiant avatar feryardiant commented on June 2, 2024

it must matches the throwed one
@jails exactly! but, as we can see the error message was

message:`TypeError` Code(0) with message "Kahlan\\Cli\\Kahlan::{closure}(): ...."

It seems like it was thrown from a closure inside Kahlan\Cli\Kahlan namespace instead of the test file, which doesn't have namespace.

Is it actually expected behavior?

from kahlan.

feryardiant avatar feryardiant commented on June 2, 2024

Also the failed message doesn't show the complete error message, or I could say it less informative.

actual:
  (object) an instance of `TypeError`
expected:
  (object) an instance of `TypeError`

To me, it sounds like "Hey, go have a test failed. You expecting an instance of TypeError, but you got an instance of TypeError". What's make it failed?

I hope it could be more informative, or at least it should behave like any other tests using toThrow(). e.g. I have a test as follow

expect(function () {
    // ...
})->toThrow(new SomeException('Some expected message'));

I'd expect the test should give me something like this if the test was failed.

It expect actual to throw a compatible exception.

actual:
  (object) an instance of `SomeException` Code(0) with message "Some actual message"
expected:
  (object) an instance of `SomeException` Code(0) with message "Some expected message"

So I can easily understand what's missing and what's makes my test failed,

from kahlan.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.