Created
April 14, 2023 19:55
-
-
Save rtio/917f0b9794b01959a216c52fe6024783 to your computer and use it in GitHub Desktop.
Validade TierDown runs on every test iteration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace MyCode; | |
| class TestClass extends TestCase { | |
| /** | |
| * MySQL table | |
| * @var array | |
| */ | |
| private array $users = []; | |
| /** | |
| * Tear Down | |
| * @return void | |
| */ | |
| public function tearDown(): void | |
| { | |
| parent::tearDown(); | |
| $this->users = []; | |
| } | |
| /** | |
| * Add new user | |
| * @param string $name | |
| * @param string $email | |
| * @param string $password | |
| * @return bool | |
| */ | |
| public function addNewUser(string $name, string $email, string $password): bool | |
| { | |
| $this->users[] = [ | |
| 'name' => $name, | |
| 'email' => $email, | |
| 'password' => $password, | |
| ]; | |
| return true; | |
| } | |
| /** | |
| * Get total users | |
| * @return int | |
| */ | |
| public function getTotalUsers(): int | |
| { | |
| return count($this->users); | |
| } | |
| /** | |
| * Provide data for testCreateUser | |
| * @return iterable | |
| */ | |
| public function createUserDataProvider(): iterable { | |
| yield 'add joao' => [ 'name' => 'João', 'email' => '[email protected]', 'password' => 'aaskxna97839' ]; | |
| yield 'add joaquim' => [ 'name' => 'Joaquim', 'email' => '[email protected]', 'password' => '23d23d23dddd' ]; | |
| yield 'add alfredo' => [ 'name' => 'Alfredo', 'email' => '[email protected]', 'password' => 'g75565j754b4' ]; | |
| } | |
| /** | |
| * Test create user | |
| * @dataProvider createUserDataProvider | |
| * @param $name | |
| * @param $email | |
| * @param $password | |
| */ | |
| public function testCreateUser($name, $email, $password): void { | |
| $this->addNewUser($name, $email, $password); | |
| $this->assertEquals(1, $this->getTotalUsers()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment