Closed theMyth721 closed 2 years ago
Could you show what error output you got?
It just throws the Exception on the Console directly and I don't get the green colours stating the test passed. I will send this shortly today. I am building this framework for a university project and is probably the last time I will code in PHP but this is the only dependency I am using
So when the wrong exception is thrown the test fails properly as expected:
But when this error is fixed and I call the public method, then it gives this error:
So the Exception is being thrown perfectly, I have an echo method in the output that is outputting everything to the screen.
I dont really want that, I want to be able to see the test pass.
When I scroll up, It doesn't say the test failed, which is good but it doesn't show the test passed:
Here is the code:
public function setConnection($sqlConfig)
{
try {
if (!array_key_exists("connection", $sqlConfig) && !array_key_exists("connections", $sqlConfig)) {
throw new DatabaseConnectionException("Database Connection Exception! Either a connection array or a connections array is required!");
}
if (isset($sqlConfig['connections'])) {
if (empty(array_keys($sqlConfig['connections'], "default"))) {
throw new DatabaseConnectionException("Database Connection Exception! Default database must be specified with multiple connections!");
}
foreach ($sqlConfig['connections'] as $connectionName => $connection) {
//
}
}
} catch (DatabaseConnectionException $th) {
$th->printStackTrace();
throw $th;
}
}
`public function testThrowsExceptionWhenNoConnectionOptPresent()
{
$this->assertThrows(DatabaseConnectionException::class, function(){
$this->dbManager->setConnection([
'abc' => 'blah',
'booboo' => 234
]);
});
}`
I am not sure if it is an error or not. The exceptions are thrown. But the test passed is not showing, instead it just outputs all the html.
I do need to separate that from the output that should go in the terminal
Is that line with unfinished test the last line of output you get from Codeception? What version of Codeception do you use?
Hi, Thank you for getting back to me. The last line I get is COMMAND DID NOT FINISH PROPERLY
That's what I expected to see.
Your application prints that HTML and then calls exit
or die
.
These functions make your code untestable.
Oh okay, so If I remove all that code, then I will get the green test passed? Thank you for your input, Are you suggesting I should not have die after? Or just not print HTML? I can configure it in some way to not print html in the console, but print in the browser
Thanks, I figured it out, I shouldn't really be doing the die.
We are talking about unit test of SqlDbManager here. It certainly shouldn't print any HTML or call die
.
Thanks, That helps a lot. I did what you suggested and it works fine now. I am building a framework for a university project & Codeception is the only dependency I used. I just want to be able to create a little CLI script that will automatically produce a unit, integrated tests when I create a new service / entity etc.. But im working on that now. It was my error, sorry about that
no problem :)
This isn't working properly. I added it as a trait. But it made no difference. Although the error is not being thrown, it is still showing the exception in the console and not showing the exception.
I doubt I will be using PHP much more, but I am building this last project in it and I would like for it to work