Help us understand the problem. What is going on with this article?

phpUnitの練習をしたのでメモ

phpUnitの練習をしたのでメモしておく

書いているテストは全てGreen

数値関連

$answer = 1 + 1;
$this->assertIsInt($answer);
$this->assertIsNotFloat($answer);
$this->assertIsNumeric($answer);
$this->assertEquals($answer,2);
$this->assertNotEquals($answer, 100);
$this->assertGreaterThan($answer, 5);
$this->assertGreaterThanOrEqual($answer, 2);
$this->assertLessThan($answer, 1);
$this->assertLessThanOrEqual($answer, 2);

boolean関連

$this->assertIsBool(true);
$this->assertIsBool(false);
$this->assertTrue(true);
$this->assertFalse(false);

Null関連

$this->assertNull(null);
$this->assertNotNull(!null);

配列関連

$users = ['konan', 'sherry', 'ran', 'jin'];
$this->assertIsArray($users);
$this->assertCount(4, $users);
$this->assertNotCount(0, $users);
$this->assertContains('konan', $users);
$this->assertNotContains('kogoro', $users);
$this->assertNotEmpty($users);

$user = ['name' => 'konan', 'age' => 6];
$this->assertArrayHasKey('name', $user);

まとめ

TDD頑張りたい

Takatoshi_Hiki
博多のwebエンジニア ブロックチェーンほんのちょっとだけワカル
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away