Skip to content

Instantly share code, notes, and snippets.

@rtio
Created April 14, 2023 19:55
Show Gist options
  • Select an option

  • Save rtio/917f0b9794b01959a216c52fe6024783 to your computer and use it in GitHub Desktop.

Select an option

Save rtio/917f0b9794b01959a216c52fe6024783 to your computer and use it in GitHub Desktop.
Validade TierDown runs on every test iteration
<?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