Skip to content

Instantly share code, notes, and snippets.

@DarkGhostHunter
Created November 26, 2018 17:55
Show Gist options
  • Save DarkGhostHunter/6f4a872729f95abce3420134f5f6faa2 to your computer and use it in GitHub Desktop.
Save DarkGhostHunter/6f4a872729f95abce3420134f5f6faa2 to your computer and use it in GitHub Desktop.
Tests an Abstract Class
<?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