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

An error was encountered when using a method not found in yii2 framework codeception #3332

Closed
tianmingxing opened this issue Jul 13, 2016 · 19 comments
Assignees
Milestone

Comments

@tianmingxing
Copy link

@tianmingxing tianmingxing commented Jul 13, 2016

When I run the test in the project directory when codecept.phar run unit, Console gives an error:

Codeception PHP Testing Framework v2.2.2
Powered by PHPUnit 5.4.6 by Sebastian Bergmann and contributors.

Unit Tests (2) -----------------------------------------------------------------------------------------------------------------------------------
- EventTest: Event is auditPHP Fatal error:  Call to a member function selectDB() on null in /var/lib/jenkins/workspace/xxx/vendor/yiisoft/yii2-mongodb/Connection.php on line 172
<pre>PHP Fatal Error &#039;yii\base\ErrorException&#039; with message &#039;Call to a member function selectDB() on null&#039;

in /var/lib/jenkins/workspace/xxx/vendor/yiisoft/yii2-mongodb/Connection.php:172

Stack trace:
#0 [internal function]: yii\base\ErrorHandler-&gt;handleFatalError()
#1 {main}</pre>

Connection.php on line 172 content: 'mongoDb' => $this->mongoClient->selectDB($name)

select DB is mongodb extend MongoClient class method, wondering why can not find a test run from the inside of the extension method.

@tianmingxing
Copy link
Author

@tianmingxing tianmingxing commented Jul 14, 2016

It has confirmed that this problem? It is not a flaw?

@Naktibalda
Copy link
Member

@Naktibalda Naktibalda commented Jul 14, 2016

It hasn't been confirmed.

@DavertMik
Copy link
Member

@DavertMik DavertMik commented Jul 16, 2016

I think this is Yii configuration issue and not a Codecepion's one

@tianmingxing
Copy link
Author

@tianmingxing tianmingxing commented Jul 18, 2016

@DavertMik I also need to provide any necessary configuration information for your reference, if any, please tell me, I hope to help me locate the point of the problem!

@tianmingxing
Copy link
Author

@tianmingxing tianmingxing commented Jul 22, 2016

This problem can solve some priority, waiting for the actual project write unit tests, progress is now stuck in here.

icron referenced this issue Jul 25, 2016
Improved Yii2 module:

* init part added to work with unit/acceptance tests
* added entryScript and entryUrl config values
* added amOnRoute method
* added amloggedAs method
* added fixtures support
* added grabComponent method
* added mocked mailer component
* grabLastSentEmail should return actual last email
* created logger in debug mode,
* mocked assetManager
@icron
Copy link

@icron icron commented Jul 25, 2016

You forgot to check for HttpException. It was in the previous version. 080dba6#comments

@tianmingxing
Copy link
Author

@tianmingxing tianmingxing commented Jul 28, 2016

@icron You mean to upgrade to the latest YII2 frame can it? I do not quite understand what you mean, describe in detail the trouble, thank you very much!

@djeux
Copy link

@djeux djeux commented Aug 8, 2016

Previously there was a check for HttpExceptions. Now all tests fail if somebody threw a NotFoundHttpException for example, which is intended behavior.

@icron
Copy link

@icron icron commented Aug 8, 2016

@tianmingxing
Copy link
Author

@tianmingxing tianmingxing commented Aug 10, 2016

@icron This problem has a specific solution for it?

@samdark
Copy link
Collaborator

@samdark samdark commented Aug 10, 2016

I don't get what the problem is. Codeception is outputting an error and continues to the next test. It seems to work as intended, isn't it?

@tianmingxing
Copy link
Author

@tianmingxing tianmingxing commented Aug 11, 2016

Call to a member function selectDB() on null This tip should not be produced, and this is the problem.

@djeux
Copy link

@djeux djeux commented Aug 11, 2016

$invite = ClientInvite::findByToken($token);

if (null === $invite) {
     throw new NotFoundHttpException("Invite not found");
} else if ($invite->isUsed) {
     throw new ForbiddenHttpException("Token already used");
}

Cest

$I->amGoingTo('try and open an invite without one');

$I->amOnPage(['/site/invite', 'token' => Yii::$app->security->generateRandomString()]);
$I->expectTo('fail');
$I->seeResponseCodeIs(404);

Works fine in 2.1.11, but fails when it shouldn't in 2.2.3

1) ClientInviteCest: Test activate
 Test  functional/ClientInviteCest.php:testActivate

  [yii\web\NotFoundHttpException] Invite not found

Scenario Steps:

 2. $I->amOnPage({"0":"\/site\/invite","token":"FosYsK-EOjEiCqe5aT1X7cdvHBHFsXSO"}) at functional/ClientInviteCest.php:23
 1. // I am going to try and open an invite without one
@samdark
Copy link
Collaborator

@samdark samdark commented Aug 11, 2016

Ah. OK. You're expecting it to fail but instead it errors.

@djeux
Copy link

@djeux djeux commented Aug 11, 2016

@samdark I expect it to continue, because NotFoundHttpException is not an exception which should fail a test, but just return a 404 page.

probably the

$I->expectTo('fail');

is just confusing

@samdark
Copy link
Collaborator

@samdark samdark commented Aug 11, 2016

It continues after the error but the fact that you expect it to fail and it's erroring isn't right.

@djeux
Copy link

@djeux djeux commented Aug 11, 2016

@samdark Ok, I'll change the text to

$I->expectTo('receive 404 error and continue');

then it should not confuse anyone. But the test should continue after receiving a HttpException like it used to, but it doesn't anymore after the update.
Before there was a check in Lib\Connector\Yii2::doRequest() to check for HttpException, its gone now after the update.

@djeux
Copy link

@djeux djeux commented Aug 11, 2016

In other words, this part is missing, which handled this case

if ($e instanceof HttpException) {
// we shouldn't discard existing output as PHPUnit preform output level verification since PHPUnit 4.2.
       $app->errorHandler->discardExistingOutput = false;
       $app->errorHandler->handleException($e);
 } elseif ($e instanceof ExitException) {
@samdark
Copy link
Collaborator

@samdark samdark commented Aug 11, 2016

Yep. Fixing that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants