Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Testing on Laravel

nunulk
January 31, 2019

Testing on Laravel

nunulk

January 31, 2019
Tweet

More Decks by nunulk

Other Decks in Technology

Transcript

  1. Testing on Laravel
    nunulk
    Laravel/Vue.jsษڧձ#7

    View full-size slide

  2. ࣗݾ঺հ
    w ໊લOVOVML ͵͵Δ͘

    w ৬ۀϑϦʔϥϯεͷ΢ΣϒΞϓϦέʔγϣϯΤϯδχΞ
    w ࢓ࣄͰ࢖͏ݴޠ΍ϑϨʔϜϫʔΫ

    1)1
    -BSBWFM +BWB4DSJQU 5ZQF4DSJQU 7VFKT
    w ޷͖ͳݴޠ1)1
    /JN $MPKVSF

    View full-size slide

  3. ࠷ۙͷؔ৺ࣄ

    View full-size slide

  4. ςετॻ͍ͯ·͔͢ʁ

    View full-size slide

  5. Laravel Testing Tips
    w 1)16OJU
    w BTTFSU&RVBMT BTTFSU4BNF BTTFSU5SVF BTTFSU'BMTF BTTFSU$POUBJOT
    BTTFSU/VMM BTTFSU5IBU BTTFSU"SSBZ)BT,FZ FUD
    w !EBUB1SPWJEFS !FYQFDUFE&YDFQUJPO !HSPVQ FUD
    w -BSBWFM
    w .PDLFSZ 'BLFS
    w .PEFM'BDUPSZ'BDLFS
    w 'BDBEF.PDLFSZ
    w %*$POUBJOFS
    w *OUFSBDUT8JUI"VUIFOUJDBUJPO .PDLT"QQMJDBUJPO4FSWJDFT
    *OUFSBDUT8JUI%BUBCBTF3FGSFTI%BUBCBTF %BUBCBTF5SBOTBDUJPOT FUD
    w BDUJOH"T BTTFSU%BUBCBTF)BT BTTFSU%BUBCBTF.JTTJOH FUD

    View full-size slide

  6. Assertions
    $this->assertNotSame(1, ‘1');
    $this->assertTrue(true);
    $this->assertContains('PHP', 'PHPUnit');
    $this->assertNotContains(2, [1, 3, 5, 7, 9]);
    $this->assertNotNull(1);
    $this->assertArrayHasKey('Laravel', [

    'PHP' => '7.2',

    'Laravel' => ‘5.7'

    ]);

    View full-size slide

  7. DataProvider
    /**
    * @param string $key1
    * @param string $key2
    * @return void
    * @dataProvider dataSomething
    */
    public function testSomething(string $key1, string $key2)
    {

    }

    public function dataSomething()
    {
    return [
    'OK' => [
    'key1' => 'value1',
    'key2' => 'value2',
    ],
    'NG:έʔε1' => [
    'key1' => 'value3',
    'key2' => 'value4',
    ],
    ];
    }

    View full-size slide

  8. Model Factory + Faker
    $factory->define(App\Task::class, function (Faker $faker) {
    return [
    'subject' => $faker->text(),
    'status' => 'open',
    ‘priority' => 'normal',
    ];
    });
    $factory->state(App\Task::class, 'doing', [
    'status' => 'doing',
    ]);
    $factory->state(App\Task::class, ‘high', [
    'priority' => 'high',
    ]);
    $task = factory(Task::class)->states([‘doing’,’high'])->make();

    View full-size slide

  9. Mocking DI
    $mockService = \Mockery::mock(‘SomeService')

    ->shouldReturn('someMethod')

    ->once()

    ->andReturn(1)

    ->getMock();

    $this->app->bind(SomeService::class,

    function () use ($mockService) {
    return $mockService;
    }

    );


    View full-size slide