Created
November 26, 2018 17:55
-
-
Save DarkGhostHunter/6f4a872729f95abce3420134f5f6faa2 to your computer and use it in GitHub Desktop.
Tests an Abstract Class
This file contains 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 Tests; | |
use PHPUnit\Framework\TestCase; | |
use MyVendor\MyPackage\AbstractClass; | |
class AbstractTest extends TestCase | |
{ | |
protected $newAnonymousClassFromAbstract; | |
protected function setUp() | |
{ | |
// Create a new instance from the Abstract Class | |
$this->newAnonymousClassFromAbstract = new class extends AbstractClass { | |
// Just a sample public function that returns this anonymous instance | |
public function returnThis() | |
{ | |
return $this; | |
} | |
}; | |
} | |
public function testAbstractClassMethod() | |
{ | |
// Let's test the public function we created in the anonymous class | |
$this->assertInstanceOf( | |
AbstractService::class, | |
$this->newAnonymousClassFromAbstract->returnThis() | |
); | |
} | |
public function testAbstractClassInternalMethod() | |
{ | |
// Let's test a function declared in the Abstract Clas | |
$this->assertTrue( | |
$this->newAnonymousClassFromAbstract->returnTrue() | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment