Skip to content

Commit

Permalink
update: use expectException() instead of @ExpectedException
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed May 1, 2021
1 parent 7df85aa commit 090241b
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 176 deletions.
4 changes: 1 addition & 3 deletions src/validator/test/unit/RequiredTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@

class RequiredTest extends TestCase
{
/**
* @expectedException \Swoft\Validator\Exception\ValidatorException
*/
public function testRequiredFailed(): void
{
// 断言异常出现
$validator = new Validator();
$validates = $this->getValidates(ValidatorRequired::class, 'testRequired');
$this->expectException(\Swoft\Validator\Exception\ValidatorException::class);
$validator->validateRequest([], $validates);
}

Expand Down
15 changes: 4 additions & 11 deletions src/validator/test/unit/UnfieldsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,21 @@ public function testUnfields(): void
$this->assertEquals($body, $data);
}

/**
* @expectedException Swoft\Validator\Exception\ValidatorException
*
* @throws ValidatorException
*/
public function testUnfieldsException(): void
{
$data = [];
$this->expectException(\Swoft\Validator\Exception\ValidatorException::class);
(new Validator())->validateRequest($data, $this->getValidates(ValidateDemo3::class, 'unfield2'));
}

/**
* @expectedException Swoft\Validator\Exception\ValidatorException
* @expectedExceptionMessage email must be a email
*
* @throws ValidatorException
*/
public function testUnfieldsException2(): void
{
$data = [
'email' => '121',
];

$this->expectException(\Swoft\Validator\Exception\ValidatorException::class);
$this->expectExceptionMessage('email must be a email');
(new Validator())->validate($data, TestValidator3::class, [], [], ['ip', 'count']);
}
}
17 changes: 5 additions & 12 deletions src/validator/test/unit/UserValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,17 @@
*/
class UserValidatorTest extends TestCase
{
/**
* @expectedException Swoft\Validator\Exception\ValidatorException
* @expectedExceptionMessage Start(fb5566f7d8580b4162f38d3c232582ae) must less than end
*
* @throws ValidatorException
*/
public function testUserFail(): void
{
$data = [
'start' => 123,
'end' => 121
];
$this->expectException(\Swoft\Validator\Exception\ValidatorException::class);
$this->expectExceptionMessage('Start(fb5566f7d8580b4162f38d3c232582ae) must less than end');
(new Validator())->validateRequest($data, $this->getValidates(ValidateUser::class, 'testUser'));
}

/**
* @expectedException Swoft\Validator\Exception\ValidatorException
* @expectedExceptionMessage Start(fb5566f7d8580b4162f38d3c232582ae) must less than end
*
* @throws ValidatorException
*/
public function testUserFail2(): void
{
$data = [
Expand All @@ -57,6 +47,9 @@ public function testUserFail2(): void
'name'
]
];

$this->expectException(\Swoft\Validator\Exception\ValidatorException::class);
$this->expectExceptionMessage('Start(fb5566f7d8580b4162f38d3c232582ae) must less than end');
(new Validator())->validate($data, UserBaseValidate::class, [], $users);
}

Expand Down
Loading

0 comments on commit 090241b

Please sign in to comment.