|
14 | 14 | */ |
15 | 15 | class TargetTest extends \PHPUnit_Framework_TestCase |
16 | 16 | { |
| 17 | + /** |
| 18 | + * Tests Target::setupPath |
| 19 | + */ |
| 20 | + public function testSetupPath() |
| 21 | + { |
| 22 | + $path = sys_get_temp_dir() . '/foo'; |
| 23 | + $filename = 'foo.txt'; |
| 24 | + $target = new Target($path, $filename); |
| 25 | + $target->setupPath(); |
| 26 | + |
| 27 | + $this->assertTrue(is_dir($target->getPath())); |
| 28 | + |
| 29 | + rmdir($target->getPath()); |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * Tests Target::setupPath |
| 34 | + * |
| 35 | + * @expectedException \phpbu\App\Exception |
| 36 | + */ |
| 37 | + public function testSetupPathNotWritable() |
| 38 | + { |
| 39 | + $filename = 'foo.txt'; |
| 40 | + $path = sys_get_temp_dir() . '/bar'; |
| 41 | + mkdir($path, 0100); |
| 42 | + |
| 43 | + |
| 44 | + try { |
| 45 | + $target = new Target($path, $filename); |
| 46 | + $target->setupPath(); |
| 47 | + } catch (\Exception $e) { |
| 48 | + chmod($target->getPath(), 0755); |
| 49 | + rmdir($target->getPath()); |
| 50 | + throw $e; |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Tests Target::setupPath |
| 56 | + * |
| 57 | + * @expectedException \phpbu\App\Exception |
| 58 | + */ |
| 59 | + public function testSetupPathCantCreateDir() |
| 60 | + { |
| 61 | + $filename = 'foo.txt'; |
| 62 | + $path = sys_get_temp_dir() . '/bar'; |
| 63 | + mkdir($path, 0100); |
| 64 | + try { |
| 65 | + $target = new Target($path . '/baz', $filename); |
| 66 | + $target->setupPath(); |
| 67 | + } catch (\Exception $e) { |
| 68 | + chmod($path, 0755); |
| 69 | + rmdir($path); |
| 70 | + throw $e; |
| 71 | + } |
| 72 | + } |
| 73 | + |
17 | 74 | /** |
18 | 75 | * Tests Target::isCompressed |
19 | 76 | */ |
@@ -396,6 +453,65 @@ public function testGetSizeFail() |
396 | 453 | $this->assertFalse(true, 'exception should be thrown'); |
397 | 454 | } |
398 | 455 |
|
| 456 | + /** |
| 457 | + * Tests Target::unlink |
| 458 | + * |
| 459 | + * @expectedException \phpbu\App\Exception |
| 460 | + */ |
| 461 | + public function testUnlinkNotExists() |
| 462 | + { |
| 463 | + $path = sys_get_temp_dir() . '/foo'; |
| 464 | + $filename = 'foo.txt'; |
| 465 | + $target = new Target($path, $filename); |
| 466 | + $target->unlink(); |
| 467 | + } |
| 468 | + |
| 469 | + /** |
| 470 | + * Tests Target::unlink |
| 471 | + * |
| 472 | + * @expectedException \phpbu\App\Exception |
| 473 | + */ |
| 474 | + public function testUnlinkNotWritable() |
| 475 | + { |
| 476 | + $path = sys_get_temp_dir() . '/foo'; |
| 477 | + $filename = 'foo.txt'; |
| 478 | + $target = new Target($path, $filename); |
| 479 | + |
| 480 | + // create the file |
| 481 | + mkdir($target->getPath(), 0755); |
| 482 | + file_put_contents($target->getPathname(), 'content'); |
| 483 | + chmod($target->getPathname(), 0444); |
| 484 | + |
| 485 | + try { |
| 486 | + $target->unlink(); |
| 487 | + } catch (\Exception $e) { |
| 488 | + chmod($target->getPathname(), 0644); |
| 489 | + unlink($target->getPathname()); |
| 490 | + rmdir($target->getPath()); |
| 491 | + throw $e; |
| 492 | + } |
| 493 | + } |
| 494 | + |
| 495 | + /** |
| 496 | + * Tests Target::unlink |
| 497 | + */ |
| 498 | + public function testUnlinkSuccess() |
| 499 | + { |
| 500 | + $path = sys_get_temp_dir() . '/foo'; |
| 501 | + $filename = 'foo.txt'; |
| 502 | + $target = new Target($path, $filename); |
| 503 | + $target->setupPath(); |
| 504 | + |
| 505 | + // create the file |
| 506 | + file_put_contents($target->getPathname(), 'content'); |
| 507 | + |
| 508 | + $target->unlink(); |
| 509 | + rmdir($target->getPath()); |
| 510 | + |
| 511 | + $this->assertFalse(file_exists($target->getPathname())); |
| 512 | + $this->assertFalse(is_dir($target->getPath())); |
| 513 | + } |
| 514 | + |
399 | 515 | /** |
400 | 516 | * Create Compressor Mock. |
401 | 517 | * |
|
0 commit comments