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
xiaoxing598 opened this Issue Jul 13, 2016 · 19 comments

Comments

Projects
None yet
6 participants
@xiaoxing598

xiaoxing598 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.

@xiaoxing598

This comment has been minimized.

Show comment
Hide comment
@xiaoxing598

xiaoxing598 Jul 14, 2016

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

xiaoxing598 commented Jul 14, 2016

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

@Naktibalda

This comment has been minimized.

Show comment
Hide comment
@Naktibalda

Naktibalda Jul 14, 2016

Member

It hasn't been confirmed.

Member

Naktibalda commented Jul 14, 2016

It hasn't been confirmed.

@DavertMik

This comment has been minimized.

Show comment
Hide comment
@DavertMik

DavertMik Jul 16, 2016

Member

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

Member

DavertMik commented Jul 16, 2016

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

@xiaoxing598

This comment has been minimized.

Show comment
Hide comment
@xiaoxing598

xiaoxing598 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!

xiaoxing598 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!

@xiaoxing598

This comment has been minimized.

Show comment
Hide comment
@xiaoxing598

xiaoxing598 Jul 22, 2016

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

xiaoxing598 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

Yii2 module improvements (#3343)
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

This comment has been minimized.

Show comment
Hide comment
@icron

icron Jul 25, 2016

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

icron commented Jul 25, 2016

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

@xiaoxing598

This comment has been minimized.

Show comment
Hide comment
@xiaoxing598

xiaoxing598 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!

xiaoxing598 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

This comment has been minimized.

Show comment
Hide comment
@djeux

djeux 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.

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

This comment has been minimized.

Show comment
Hide comment
@icron

icron commented Aug 8, 2016

@xiaoxing598

This comment has been minimized.

Show comment
Hide comment
@xiaoxing598

xiaoxing598 Aug 10, 2016

@icron This problem has a specific solution for it?

xiaoxing598 commented Aug 10, 2016

@icron This problem has a specific solution for it?

@samdark

This comment has been minimized.

Show comment
Hide comment
@samdark

samdark Aug 10, 2016

Collaborator

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?

Collaborator

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?

@xiaoxing598

This comment has been minimized.

Show comment
Hide comment
@xiaoxing598

xiaoxing598 Aug 11, 2016

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

xiaoxing598 commented Aug 11, 2016

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

@djeux

This comment has been minimized.

Show comment
Hide comment
@djeux

djeux 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

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

This comment has been minimized.

Show comment
Hide comment
@samdark

samdark Aug 11, 2016

Collaborator

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

Collaborator

samdark commented Aug 11, 2016

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

@djeux

This comment has been minimized.

Show comment
Hide comment
@djeux

djeux 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

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

This comment has been minimized.

Show comment
Hide comment
@samdark

samdark Aug 11, 2016

Collaborator

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

Collaborator

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

This comment has been minimized.

Show comment
Hide comment
@djeux

djeux 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 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

This comment has been minimized.

Show comment
Hide comment
@djeux

djeux 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) {

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

This comment has been minimized.

Show comment
Hide comment
@samdark

samdark Aug 11, 2016

Collaborator

Yep. Fixing that.

Collaborator

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