예제 #1
0
파일: Dir.spec.php 프로젝트: crysalead/dir
            $stat = stat($path);
            $mode = $stat['mode'] & 0777;
            expect($mode)->toBe(0755);
        });
        it("creates a nested directory with a specific mode", function () {
            $path = $this->tmpDir . '/My/Nested/Directory';
            $actual = Dir::make($path, ['mode' => 0777]);
            expect($actual)->toBe(true);
            expect(file_exists($path))->toBe(true);
            $stat = stat($path);
            $mode = $stat['mode'] & 0777;
            expect($mode)->toBe(0777);
        });
        it("creates multiple nested directories in a single call", function () {
            $paths = [$this->tmpDir . '/My/Nested/Directory', $this->tmpDir . '/Sub/Nested/Directory'];
            $actual = Dir::make($paths);
            expect($actual)->toBe(true);
            foreach ($paths as $path) {
                expect(file_exists($path))->toBe(true);
            }
        });
    });
    describe("::tempnam()", function () {
        it("uses the system temp directory by default", function () {
            $dir = Dir::tempnam(null, 'spec');
            $temp = sys_get_temp_dir();
            expect($dir)->toMatch('~^' . $temp . '/spec~');
            Dir::remove($dir);
        });
    });
});
예제 #2
0
 });
 it("uses php://input as body message by default", function () {
     $temp = Dir::tempnam(sys_get_temp_dir(), 'spec');
     $filename = tempnam($temp, 'foo');
     $handler = fopen($filename, 'w');
     fwrite($handler, 'Hello World');
     fclose($handler);
     Monkey::patch('fopen', function ($name, $mode, $use_include_path = false) use($filename) {
         if ($name === 'php://input') {
             $name = $filename;
         }
         return fopen($name, $mode, $use_include_path);
     });
     $request = Request::ingoing();
     expect($request->body())->toBe('Hello World');
     Dir::remove($temp, ['recursive' => true]);
 });
 it("normalizes deep `\$_FILES` structure", function () {
     $_FILES = ['files' => ['name' => ['file 2.jpg', 'file 3.jpg', 'file 4.jpg'], 'type' => ['image/jpeg', 'image/jpeg', 'image/jpeg'], 'tmp_name' => ['/private/var/tmp/phpF5vsky', '/private/var/tmp/phphRJ2zW', '/private/var/tmp/phprI92L1'], 'error' => [0, 0, 0], 'size' => [418, 418, 418]]];
     $request = Request::ingoing();
     expect($request->data())->toEqual(['files' => [['name' => 'file 2.jpg', 'type' => 'image/jpeg', 'tmp_name' => '/private/var/tmp/phpF5vsky', 'error' => 0, 'size' => 418], ['name' => 'file 3.jpg', 'type' => 'image/jpeg', 'tmp_name' => '/private/var/tmp/phphRJ2zW', 'error' => 0, 'size' => 418], ['name' => 'file 4.jpg', 'type' => 'image/jpeg', 'tmp_name' => '/private/var/tmp/phprI92L1', 'error' => 0, 'size' => 418]]] + $_POST);
 });
 it("normalizes nested `\$_FILES` structure", function () {
     $_FILES = ['Image' => ['name' => ['file' => 'file 5.jpg'], 'type' => ['file' => 'image/jpeg'], 'tmp_name' => ['file' => '/private/var/tmp/phpAmSDL4'], 'error' => ['file' => 0], 'size' => ['file' => 418]]];
     $request = Request::ingoing();
     expect($request->data())->toEqual(['Image' => ['file' => ['name' => 'file 5.jpg', 'type' => 'image/jpeg', 'tmp_name' => '/private/var/tmp/phpAmSDL4', 'error' => 0, 'size' => 418]]] + $_POST);
 });
 it("normalizes deeply nested `\$_FILES` structure", function () {
     $_FILES = ['Photo' => ['name' => ['files' => [0 => 'file 6.jpg', 1 => 'file 7.jpg', 2 => 'file 8.jpg']], 'type' => ['files' => [0 => 'image/jpeg', 1 => 'image/jpeg', 2 => 'image/jpeg']], 'tmp_name' => ['files' => [0 => '/private/var/tmp/php2eViak', 1 => '/private/var/tmp/phpMsC5Pp', 2 => '/private/var/tmp/phpm2nm98']], 'error' => ['files' => [0 => 0, 1 => 0, 2 => 0]], 'size' => ['files' => [0 => 418, 1 => 418, 2 => 418]]]];
     $request = Request::ingoing();
     expect($request->data())->toEqual(['Photo' => ['files' => [['name' => 'file 6.jpg', 'type' => 'image/jpeg', 'tmp_name' => '/private/var/tmp/php2eViak', 'error' => 0, 'size' => 418], ['name' => 'file 7.jpg', 'type' => 'image/jpeg', 'tmp_name' => '/private/var/tmp/phpMsC5Pp', 'error' => 0, 'size' => 418], ['name' => 'file 8.jpg', 'type' => 'image/jpeg', 'tmp_name' => '/private/var/tmp/phpm2nm98', 'error' => 0, 'size' => 418]]]] + $_POST);