Created
May 23, 2012 03:42
-
-
Save colindecarlo/2773143 to your computer and use it in GitHub Desktop.
testing protected method indirectly
This file contains hidden or 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 | |
// interesting bits | |
public function test_protected_persist_indirectly_via_public_persist_success() | |
{ | |
$filePersister = new File($_FILES, $this->logger); | |
$this->assertTrue($filePersister->persist()); | |
$persistedLocation = \PHPUnit_Framework_Assert::readAttribute($filePersister, '_location'); | |
$this->assertRegExp('/UL-/', $persistedLocation); | |
$this->assertTrue(file_exists($persistedLocation)); | |
$this->assertEquals("Hello World\n", file_get_contents($persistedLocation)); | |
} | |
public function test_protected_persist_indirectly_via_public_persist_failure() | |
{ | |
$filePersisterMock = $this->getMockBuilder('GPUG\Examples\Persister\File') | |
->setConstructorArgs(array($_FILES, $this->logger)) | |
->setMethods(array('_moveUploadedFile')) | |
->getMock(); | |
$filePersisterMock->expects($this->once()) | |
->method('_moveUploadedFile') | |
->will($this->returnValue(false)); | |
try { | |
$filePersisterMock->persist(); | |
} catch (\Exception $e) { | |
$this->assertNull(\PHPUnit_Framework_Assert::readAttribute($filePersisterMock, '_location')); | |
$this->assertEquals('We were unable to store your file, maybe retry a little later?', $e->getMessage()); | |
$pe = $e->getPrevious(); | |
$this->assertNotNull($pe); | |
$this->assertEquals('error moving uploaded file', $pe->getMessage()); | |
return; | |
} | |
$this->fail('Expected exception was not thrown in test_protected_persist_indirectly_via_public_persist_failure'); | |
} | |
// interesting bits |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment