Skip to content

Commit

Permalink
fix bug of unlink method and modify unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
puritys committed Nov 26, 2014
1 parent bc12425 commit 232fcd4
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ before_script:
- "npm install -g mocha"
- "npm install istanbul"
- "npm install coveralls"
- "npm install phplike"
- "npm build ./"


Expand Down
8 changes: 5 additions & 3 deletions nodejs/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ function rmdir(dir, isForce) {//{{{
}
};//}}}

function unlink(filename) {
return fs.unlinkSync(filename);
}


/*
* @param filename
Expand Down Expand Up @@ -100,9 +104,6 @@ exports.mkdir = function(dirName) {/*{{{*/
}
};/*}}}*/

exports.unlink = function (filename) {
return fs.unlinkSync(filename);
}



Expand All @@ -114,3 +115,4 @@ exports.readdir = readdir;
exports.is_dir = is_dir;
exports.is_file = is_file;
exports.rmdir = rmdir;
exports.unlink = unlink;
30 changes: 29 additions & 1 deletion tests/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ describe('Test function: is_dir, file.js', function () {
it('Test directory is exist.', function() {
var isDir = phplikeMod.is_dir("tests");
assert.equal(true, isDir);
})
});

it('File is not a dir.', function() {
var file = 'tests/global.js';
var res = phplikeMod.is_dir(file);
assert.equal(false, res);
});

});

Expand All @@ -40,12 +46,25 @@ describe('File Handle', function () {

});

it('read a not exist file', function () {
var content = phplikeMod.file_get_contents("./tests/file.jsxx");
assert.equal("", content);

});

it('write file', function () {
phplikeMod.file_put_contents("./tests/tmp", "test");
var content = phplikeMod.file_get_contents("./tests/tmp");
assert.equal("test", content);
});

it('write a binary content into file', function () {
phplikeMod.file_put_contents("./tests/tmp2", "test", "binary");
var content = phplikeMod.file_get_contents("./tests/tmp2");
assert.equal("test", content);
phplikeMod.unlink("./tests/tmp2");
});

it('delete file', function () {
phplikeMod.file_put_contents("./tests/tmp", "test");
var content = phplikeMod.file_get_contents("./tests/tmp");
Expand All @@ -66,8 +85,17 @@ describe('dir handle', function () {
assert.equal(true, isDir);
});

it('create single level dir', function () {
phplikeMod.mkdir("test_dir");
var isDir = phplikeMod.is_dir("test_dir");
assert.equal(true, isDir);
phplikeMod.rmdir("test_dir");
});

it('delete dir - force', function() {
var isForce = true;
phplikeMod.mkdir(dir);
phplikeMod.file_put_contents(dir + "/tmp", "test");
phplikeMod.rmdir("./tests/test", isForce);
isDir = phplikeMod.is_dir(dir);
assert.equal(false, isDir);
Expand Down
11 changes: 9 additions & 2 deletions tests/global.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// global function test
// global function test and test the phplike module which has already installed.

global.UNIT_TEST = true;
require('./../nodejs/index.js');
require('phplike');

var assert = require("assert");

Expand Down Expand Up @@ -29,7 +29,14 @@ describe('Test global function: core function', function() {
assert.equal("dGVzdA==", res);
});

});

describe('Test global function: is_dir', function() {
it('File is not a dir.', function() {
var file = 'tests/global.js';
var res = is_dir(file);
assert.equal(false, res);
});

});

Expand Down

0 comments on commit 232fcd4

Please sign in to comment.