getMockForAbstractClass(EmailField::class, ["testName"]); $this->assertEquals('testName', $stub->getName()); $this->assertInstanceOf(EmailField::class, $stub); } /** * @depends testFoundation */ public function testBase() { // Generate the field $field = new EmailField("testName"); $field->setFormName("testForm"); // Assert expected returns $html = $field->generateHtml(); $this->assertTrue(str_starts_with($html, "assertTrue(str_ends_with($html, ">")); $this->assertTrue(str_contains($html, "type='email'")); $this->assertTrue(str_contains($html, "name='testName'")); $this->assertTrue(str_contains($html, "id='testForm_testName'")); } /** * @depends testBase */ public function testValidator() { // Generate a basic field $field = new EmailField("testName"); $field->setFormName("testForm"); // Set a value that is not an email $field->setValue("totallynot#an_email"); $this->assertFalse($field->validate()); $this->assertEquals(['TestName is not a valid email address.'], $field->getErrors()); // Set a value that is valid $field->setValue("name@example.com"); $this->assertTrue($field->validate()); $this->assertEmpty($field->getErrors()); } }