PHPUnit Laravel Couldn't Update In Ut
I have been meeting an annoying problem when using phpunit. I found my database is not updated, after an eloquent method is triggered, so the result of the unit test is always wrong.
The code is as below:
$testTaskUser = TestTaskUser::find(\SeederConstants::$TEST_TASK_USER_ID); $testTaskUser->update(array( 'status' => TestTaskUserStatus::$INITIALIZED )); $this->assertEquals($testTaskUser->status,TestTaskUserStatus::$INITIALIZED); //This assert fails because the 'status' is not updated in the db, which is //Very confusing to me
The phpserver and mysql is running in vm in Ubuntu, on my Macbook air. Anybody can help will be really appreciated.
You should make sure that for
TestTaskUser user you've added
status column to
protected $fillable = ['status'];
Please look at mass assignment section
Alternatively you can change your code from:
$testTaskUser->update(array( 'status' => TestTaskUserStatus::$INITIALIZED ));
$testTaskUser->status = TestTaskUserStatus::$INITIALIZED; $testTaskUser->save();
and in this case you don't need to fill in
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?