Exemple #1
0
            $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);
        });
    });
});
Exemple #2
0
 });
 describe("::ingoing()", function () {
     beforeEach(function () {
         $this->globals = defineGlobals();
     });
     it("creates a request from globals", function () {
         $request = Request::ingoing();
         expect($request->export())->toEqual(['basePath' => '/base/path/webroot', 'locale' => null, 'data' => $_FILES + $_POST, 'params' => [], 'env' => $request->env, 'method' => 'GET', 'scheme' => 'http', 'version' => '1.1', 'host' => 'localhost', 'port' => 80, 'path' => '/app', 'query' => '?get=value', 'fragment' => '', 'username' => null, 'password' => null, 'url' => 'http://localhost/app?get=value', 'stream' => $request->stream()]);
     });
     it("supports url rewriting", function () {
         $this->globals = defineGlobals(['SERVER' => ['REQUEST_URI' => '/base/path/app?get=value']]);
         $request = Request::ingoing();
         expect($request->export())->toEqual(['basePath' => '/base/path', 'locale' => null, 'data' => $_FILES + $_POST, 'params' => [], 'env' => $request->env, 'method' => 'GET', 'scheme' => 'http', 'version' => '1.1', 'host' => 'localhost', 'port' => 80, 'path' => '/app', 'query' => '?get=value', 'fragment' => '', 'username' => null, 'password' => null, 'url' => 'http://localhost/app?get=value', 'stream' => $request->stream()]);
     });
     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 () {