Skip to content

Commit d930c04

Browse files
author
Greg Bowler
committed
Initial test
1 parent eee9067 commit d930c04

File tree

8 files changed

+50
-11
lines changed

8 files changed

+50
-11
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ build.json:
3232
"name": "Babel transpile",
3333
"command": "./node_modules/.bin/babel",
3434
"args": "src/script/main.js -o www/script.js",
35-
"requires": {
35+
"require": {
3636
"node": "^8.4",
3737
"@command": "^6.0"
3838
}
@@ -42,7 +42,7 @@ build.json:
4242
"name": "Sass compilation",
4343
"command": "sass",
4444
"args": "src/style/main.scss www/style.css",
45-
"requires": {
45+
"require": {
4646
"ruby": "2.4.2",
4747
"@command": "3.5.1"
4848
}

src/Build.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ class Build {
88

99
public function __construct(string $buildConfigDir) {
1010
$buildConfigFilePath = $buildConfigDir . "/build.json";
11-
$this->taskList = new TaskList($buildConfigFilePath, $buildConfigDir);
11+
$this->taskList = new TaskList(
12+
$buildConfigFilePath,
13+
$buildConfigDir
14+
);
1215
}
1316

1417
public function check():int {

src/Task.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Task {
1515

1616
protected $fileHashList = [];
1717

18-
public function __construct(string $basePath, string $pathMatch, $details) {
18+
public function __construct(\object $details, string $pathMatch, string $basePath = "") {
1919
$basePath = $this->expandRelativePath($basePath);
2020
$this->pathMatch = $pathMatch;
2121
$this->absolutePath = implode(DIRECTORY_SEPARATOR, [
@@ -56,12 +56,12 @@ public function build():bool {
5656
return $changes;
5757
}
5858

59-
protected function setDetails($details):void {
59+
protected function setDetails(object $details):void {
6060
$this->execute = $details->execute;
6161
$this->name = $details->name ?? $details->execute->command;
6262

63-
if(isset($details->requires)) {
64-
foreach($details->requires as $key => $value) {
63+
if(isset($details->require)) {
64+
foreach($details->require as $key => $value) {
6565
$this->requirements []= new Requirement(
6666
$key,
6767
$value
@@ -84,7 +84,7 @@ protected function execute():void {
8484
}
8585

8686
protected function expandRelativePath(string $basePath):string {
87-
if($basePath[0] === ".") {
87+
if($basePath[0] !== "/") {
8888
$basePath = getcwd() . substr(
8989
$basePath,
9090
1

src/TaskList.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ public function __construct(string $jsonFilePath, string $baseDir) {
2323
foreach($obj as $pathMatch => $details) {
2424
$this->pathMatches []= $pathMatch;
2525
$this->tasks[$pathMatch] = new Task(
26-
$baseDir,
27-
$pathMatch,
28-
$details
26+
$details, $pathMatch, $baseDir
2927
);
3028
}
3129
}

test/unit/BuildTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
namespace Gt\Build\Test;
3+
4+
use PHPUnit\Framework\TestCase;
5+
6+
class BuildTest extends TestCase {
7+
8+
}

test/unit/Helper/Helper.php

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
namespace Gt\Build\Test\Helper;
3+
4+
class Helper {
5+
6+
}

test/unit/TaskListTest.php

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
namespace Gt\Build\Test;
3+
4+
use PHPUnit\Framework\TestCase;
5+
6+
class TaskListTest extends TestCase {
7+
}

test/unit/TaskTest.php

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
namespace Gt\Build\Test;
3+
4+
use Gt\Build\Task;
5+
use PHPUnit\Framework\TestCase;
6+
use stdClass;
7+
8+
class TaskTest extends TestCase {
9+
public function testCheckRequirements() {
10+
$details = new StdClass();
11+
$details->require = new StdClass();
12+
$details->require->{"centScript"} = "100";
13+
$details->require->{"decScript"} = "10";
14+
15+
$task = new Task($details, "**/*");
16+
}
17+
}

0 commit comments

Comments
 (0)