教你一步一步写一个phpunit testcase(8)

发表于:2017-06-01来源:叶左左作者:叶左左点击数: 标签:PHPUnit
0 ]; $user = $obj[ 1 ]; // 使用者取消报名 $event-unReserve($user); $unReserveExpectedCount = 0 ; // 预期报名人数 $this -assertEquals($unReserveExpectedCount, $event-getAttendNumber()); //
0]; $user = $obj[1]; // 使用者取消报名 $event->unReserve($user); $unReserveExpectedCount = 0; // 预期报名人数 $this->assertEquals($unReserveExpectedCount, $event->getAttendNumber()); // 报名清单中没有已经取消报名的人 $this->assertNotContains($user, $event->attendArr); } /** * @param $eventId * @param $eventName * @param $eventStartDate * @param $eventEndDate * @param $eventAttendLimit * @dataProvider eventsDataProvider */ public function testAttendeeLimitReserve($eventId, $eventName, $eventStartDate, $eventEndDate, $eventAttendLimit) { // 测试报名人数限制 $event = new \PHPUnitEventDemo\Event($eventId, $eventName, $eventStartDate, $eventEndDate, $eventAttendLimit); $userNumber = 6; // 建立不同使用者报名 for ($userCount = 1; $userCount < $userNumber; $userCount++) { $userId = $userCount; $userName = 'User ' . $userId; $userEmail = 'user' . $userId . '@zoco.space'; $user = new \PHPUnitEventDemo\User($userId, $userName, $userEmail); $reservedResult = $event->reserve($user); // 报名人數是否超过 if ($userCount > $eventAttendLimit) { // 无法报名 $this->assertFalse($reservedResult); } else { $this->assertTrue($reservedResult); } } } /** * @return array */ public

原文转自:http://www.jianshu.com/p/ba6829a6f3ec