MongolidLaravel\MongolidModelTest::testShouldHashAttributesOnSaveAndUpdate PHP Method

testShouldHashAttributesOnSaveAndUpdate() public method

    public function testShouldHashAttributesOnSaveAndUpdate($method)
    {
        // Set
        $dataMapper = m::mock(DataMapper::class);
        $this->app->instance(DataMapper::class, $dataMapper);
        $hasher = m::mock(Hasher::class);
        $this->app->instance(Hasher::class, $hasher);
        $model = new class extends MongolidModel
        {
            protected $collection = 'users';
            protected $hashedAttributes = ['password'];
        };
        $model->storeOriginalAttributes();
        $model->password = '123456';
        $model->password_confirmation = '123456';
        // Expectations
        $dataMapper->shouldReceive($method)->once()->withAnyArgs()->andReturn(true);
        $hasher->shouldReceive('make')->once()->with('123456')->andReturn('HASHED_PASSWORD');
        // Actions
        $result = $model->{$method}();
        // Assertions
        $this->assertTrue($result);
        $this->assertEquals('HASHED_PASSWORD', $model->password);
        $this->assertNull($model->password_confirmation);
    }