1515use Codeception \Lib \Interfaces \ActiveRecord ;
1616use Codeception \Lib \Interfaces \PartedModule ;
1717use Codeception \TestInterface ;
18+ use PHPUnit \Framework \Assert ;
1819use ReflectionClass ;
1920use RuntimeException ;
2021use Yii ;
2526use yii \mail \BaseMessage ;
2627use yii \mail \MessageInterface ;
2728use yii \test \Fixture ;
28- use yii \web \Application ;
29+ use yii \web \Application as WebApplication ;
2930use yii \web \IdentityInterface ;
3031
3132/**
@@ -252,7 +253,7 @@ final class Yii2 extends Framework implements ActiveRecord, PartedModule
252253 private TransactionForcer $ transactionForcer ;
253254
254255 /**
255- * @var array<mixed> The contents of $_SERVER upon initialization of this object.
256+ * @var array<mixed> The contents of upon initialization of this object.
256257 * This is only used to restore it upon object destruction.
257258 * It MUST not be used anywhere else.
258259 */
@@ -625,34 +626,34 @@ public function grabFixture(string $name, null|string $index = null): Fixture|\y
625626 *
626627 * ``` php
627628 * <?php
628- * $user_id = $I->haveRecord('app\models\ User', array( 'name' => 'Davert') );
629+ * $user_id = $I->haveRecord(model: User::class, attributes: [ 'name' => 'Davert'] );
629630 * ?>
630631 * ```
631632 *
632633 * @template T of \yii\db\ActiveRecord
633634 * @param class-string<T> $model
634- * @param array<string, mixed> $attributes
635+ * @param array<string, mixed> $attributes
635636 * @part orm
637+ * @return int|string|array<string, int|string> The primary key
636638 */
637- public function haveRecord (string $ model , $ attributes = []): mixed
639+ public function haveRecord (string $ model , $ attributes = []): int | string | array
638640 {
639641 /**
640- * @var T $record
641- */
642+ * @var T $record
643+ */
642644 $ record = \Yii::createObject ($ model );
643645 $ record ->setAttributes ($ attributes , false );
644- $ res = $ record ->save (false );
645- if (! $ res ) {
646- $ this ->fail ("Record $ model was not saved: " . \yii \helpers \Json::encode ($ record ->errors ));
646+ if (! $ record ->save (false )) {
647+ Assert::fail ("Record $ model was not saved: " . \yii \helpers \Json::encode ($ record ->errors ));
647648 }
648- return $ record ->primaryKey ;
649+ return $ record ->getPrimaryKey () ;
649650 }
650651
651652 /**
652653 * Checks that a record exists in the database.
653654 *
654655 * ```php
655- * $I->seeRecord('app\models\ User', array( 'name' => 'davert') );
656+ * $I->seeRecord(model: User::class, attributes: [ 'name' => 'davert'] );
656657 * ```
657658 *
658659 * @param class-string<\yii\db\ActiveRecord> $model
@@ -663,7 +664,7 @@ public function seeRecord(string $model, array $attributes = []): void
663664 {
664665 $ record = $ this ->findRecord ($ model , $ attributes );
665666 if (! $ record ) {
666- $ this -> fail ("Couldn't find $ model with " . json_encode ($ attributes ));
667+ Assert:: fail ("Couldn't find $ model with " . json_encode ($ attributes ));
667668 }
668669 $ this ->debugSection ($ model , json_encode ($ record ));
669670 }
@@ -672,7 +673,7 @@ public function seeRecord(string $model, array $attributes = []): void
672673 * Checks that a record does not exist in the database.
673674 *
674675 * ```php
675- * $I->dontSeeRecord('app\models\ User', array( 'name' => 'davert') );
676+ * $I->dontSeeRecord(User::class, attributes: [ 'name' => 'davert'] );
676677 * ```
677678 *
678679 * @param class-string<\yii\db\ActiveRecord> $model
@@ -684,15 +685,15 @@ public function dontSeeRecord(string $model, array $attributes = []): void
684685 $ record = $ this ->findRecord ($ model , $ attributes );
685686 $ this ->debugSection ($ model , json_encode ($ record ));
686687 if ($ record ) {
687- $ this -> fail ("Unexpectedly managed to find $ model with " . json_encode ($ attributes ));
688+ Assert:: fail ("Unexpectedly managed to find $ model with " . json_encode ($ attributes ));
688689 }
689690 }
690691
691692 /**
692693 * Retrieves a record from the database
693694 *
694695 * ```php
695- * $category = $I->grabRecord('app\models\ User', array( 'name' => 'davert') );
696+ * $category = $I->grabRecord(User::class, attributes: [ 'name' => 'davert'] );
696697 * ```
697698 *
698699 * @param class-string<\yii\db\ActiveRecord> $model
0 commit comments