![]() ![]() ![]() See Db Module Interacting with the Framework If that’s not your required behavior, change the settings of the Db module for the current suite. The database will be cleaned and populated after each test, the same way it happens for acceptance and functional tests. To enable the database functionality in unit tests, make sure the Db module is included setName ( 'Miles' ) $user -> setSurname ( 'Davis' ) $user -> save () $this -> assertEquals ( 'Miles Davis', $user -> getFullName ()) $this -> tester -> seeInDatabase ( 'users', ) } Stubs can also be created using static methods from Codeception\Stub class. create a stub with find method replaced $userRepository = $this -> make ( UserRepository :: class, ) $userRepository -> find ( 1 ) // => User // create a dummy $userRepository = $this -> makeEmpty ( UserRepository :: class ) // create a stub with all methods replaced except one $user = $this -> makeEmptyExcept ( User :: class, 'validate' ) $user -> validate ( $data ) // create a stub by calling constructor and replacing a method $user = $this -> construct ( User :: class, , ) // create a stub by calling constructor with empty methods $user = $this -> constructEmpty ( User :: class, ) // create a stub by calling constructor with empty methods $user = $this -> constructEmptyExcept ( User :: class, 'getName', ) $user -> getName () // => davert $user -> setName ( 'jane' ) // => this method is empty This tiny library adds more readable assertions, which is quite nice, if you are always confusedĪbout which argument in assert calls is expected and which one is actual: ![]() You may add Codeception\Verify for BDD-style assertions. The most common are:Īssertion methods come from PHPUnit. There are pretty many assertions you can use inside tests. This can be patched in ActiveResource.SetName ( null ) $this -> assertFalse ( $user -> validate ()) $user -> setName ( 'toolooooongnaaaaaaameeee' ) $this -> assertFalse ( $user -> validate ()) $user -> setName ( 'davert' ) $this -> assertTrue ( $user -> validate ()) } } Assertions (edit : according to the website the bug was fixed in the latest release: ) The reason for that is that the class is unable to create the correct singular form from the pluralized version of the entity name.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |