Laravel 5 unit testing Update

I have the following function in one of my controller

public function update($id)
    {
        $bank = $this->bankService->findById($id, new ApiRequest());

        $bank->name = Input::json('name');
        $bank->iban = Input::json('iban');
        $bank->swift_code = Input::json('swift_code');

        return $this->bankService->update($bank);
    }

I am trying to write a unit test for the success update, I have the following code:

public function testUpdateOne()
    {
        // Prepare
        $bank = new Bank();
        $bank->id = 1;
        $bank->name = 'Bpb';
        $bank->iban = 'ib';
        $bank->swift_code = 'swift';

        $service = Mockery::mock('BankServicesBankService');
        $service->shouldReceive('findById')
            ->once()->andReturn($bank);

        $bankUpdate = new Bank();
        $bankUpdate->id = 1;
        $bankUpdate->name = 'proo';
        $bankUpdate->iban = 'test';
        $bankUpdate->swift_code = 'sw';

        $service->shouldReceive('update')
            ->once()->andReturn($bankUpdate);

        $this->app->instance('BankServicesBankService', $service);
        $controller = new BankController($service);

        // Act
        $find = json_decode($controller->show($bank->id));
        $result = json_decode($controller->update($find->id));

        // Assert
        $this->assertEquals($find->id, $result->id);
        $this->assertNotEquals($find->name, $result->name);
        $this->assertNotEquals($find->iban, $result->iban);
        $this->assertNotEquals($find->swift_code, $result->swift_code);
    }

I dont have any error but im not sure if im testing the right way for this test.

Any ideas?


Source: laravel

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.