/00-initial-set-up.php Secret
Created
April 18, 2018 16:19
Star
You must be signed in to star a gist
[PHP] Writing Unit Tests with PHPUnit, Part 2: The Tear Down
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 Pressware\Acme\Tests\API; | |
use PHPUnit\Framework\TestCase; | |
class AcmeFileTest extends TestCase | |
{ | |
private $filename; | |
private $content; | |
public function setUp() | |
{ | |
$this->filename = 'testFile.txt'; | |
$this->content = 'This is a string of data that is meant to be written to the file.'; | |
} | |
// More to come... | |
} |
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 Pressware\Acme\Tests\API; | |
use PHPUnit\Framework\TestCase; | |
class AcmeFileTest extends TestCase | |
{ | |
private $filename; | |
private $content; | |
public function setUp() | |
{ | |
$this->filename = 'testFile.txt'; | |
$this->content = 'This is a string of data that is meant to be written to the file.'; | |
} | |
public function testWriteReadData() | |
{ | |
// Writes the content to the file with the given filename. | |
$fileHandle = fopen($this->filename, 'w'); | |
fwrite($fileHandle, $this->content); | |
fclose($fileHandle); | |
// Reads the contents of the file that was just written | |
$fileHandle = fopen($this->filename, 'r'); | |
$contents = fread($fileHandle, filesize($this->filename)); | |
fclose($fileHandle); | |
$this->assertSame($this->content, $contents); | |
} | |
// More to come.. | |
} |
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 Pressware\Acme\Tests\API; | |
use PHPUnit\Framework\TestCase; | |
class AcmeFileTest extends TestCase | |
{ | |
private $filename; | |
private $content; | |
public function setUp() | |
{ | |
$this->filename = 'testFile.txt'; | |
$this->content = 'This is a string of data that is meant to be written to the file.'; | |
} | |
public function testWriteReadData() | |
{ | |
// Writes the content to the file with the given filename. | |
$fileHandle = fopen($this->filename, 'w'); | |
fwrite($fileHandle, $this->content); | |
fclose($fileHandle); | |
// Reads the contents of the file that was just written | |
$fileHandle = fopen($this->filename, 'r'); | |
$contents = fread($fileHandle, filesize($this->filename)); | |
fclose($fileHandle); | |
$this->assertSame($this->content, $contents); | |
} | |
public function tearDown() | |
{ | |
if (file_exists($this->filename)) { | |
unlink($this->filename); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment