Skip to content

Commit d097568

Browse files
committed
#12 : Unit Tests
1 parent fc4e83b commit d097568

24 files changed

+1415
-297
lines changed

samples/Sample_01_Simple.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
$objTask1Res = $objTask1->getResources();
3939
echo 'Resources "Start of the project"'.EOL;
4040
foreach ($objTask1Res as $res){
41-
echo ' > '.$objPHPProject->getResource($res)->getTitle().EOL;;
41+
echo ' > '.$objPHPProject->getResource($res)->getTitle().EOL;;
4242
}
4343

4444
$objTask2 = $objPHPProject->createTask();
@@ -54,7 +54,7 @@
5454
$objTask21Res = $objTask21->getResources();
5555
echo 'Resources "Analysis Code"'.EOL;
5656
foreach ($objTask21Res as $res){
57-
echo ' > '.$objPHPProject->getResource($res)->getTitle().EOL;;
57+
echo ' > '.$objPHPProject->getResource($res)->getTitle().EOL;;
5858
}
5959

6060
$objTask22 = $objTask2->createTask();
@@ -66,5 +66,5 @@
6666
// Save file
6767
echo write($objPHPProject, basename(__FILE__, '.php'), $writers);
6868
if (!CLI) {
69-
include_once 'Sample_Footer.php';
69+
include_once 'Sample_Footer.php';
7070
}

samples/Sample_02_ReadGanttProject.php

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use PhpOffice\PhpProject\PHPProject;
66
use PhpOffice\PhpProject\IOFactory;
7-
7+
88
// Create new PHPProject object
99
echo date('H:i:s') . ' Create new PHPProject object'.EOL;
1010
$objReader = IOFactory::createReader('GanttProject');
@@ -29,51 +29,51 @@
2929
echo date('H:i:s') . ' Get ressources'.EOL;
3030
$oResources = $objPHPProject->getAllResources();
3131
foreach ($oResources as $item){
32-
echo 'Resource :'.$item->getTitle().EOL;
32+
echo 'Resource :'.$item->getTitle().EOL;
3333
}
3434
echo EOL;
3535

3636
// Tasks
3737
echo date('H:i:s') . ' Get tasks'.EOL;
3838
$oTasks = $objPHPProject->getAllTasks();
3939
foreach ($oTasks as $item){
40-
echo 'Task :'.$item->getName().EOL;
41-
echo ' >> Duration :'.$item->getDuration().EOL;
42-
echo ' >> StartDate :'.$item->getStartDate().EOL;
43-
echo ' >> EndDate :'.$item->getEndDate().EOL;
44-
echo ' >> Progress :'.$item->getProgress().EOL;
45-
echo ' >> Resources :'.EOL;
46-
$oTaskResources = $item->getResources();
47-
if(!empty($oTaskResources)){
48-
foreach ($oTaskResources as $itemRes){
49-
echo ' >>>> Resource :'.$objPHPProject->getResource($itemRes)->getTitle().EOL;
50-
}
51-
}
52-
53-
echo ' >> SubTasks :'.EOL;
54-
$oSubTasks = $item->getTasks();
55-
if(!empty($oSubTasks)){
56-
foreach ($oSubTasks as $itemSub){
57-
echo ' >>>> Task :'.$itemSub->getName().EOL;
58-
echo ' >>>>>> Duration :'.$itemSub->getDuration().EOL;
59-
echo ' >>>>>> StartDate :'.$itemSub->getStartDate().EOL;
60-
echo ' >>>>>> EndDate :'.$itemSub->getEndDate().EOL;
61-
echo ' >>>>>> Progress :'.$itemSub->getProgress().EOL;
62-
echo ' >>>>>> Resources :'.EOL;
63-
$oTaskResources = $itemSub->getResources();
64-
if(!empty($oTaskResources)){
65-
foreach ($oTaskResources as $itemRes){
66-
echo ' >>>>>>>> Resource :'.$objPHPProject->getResource($itemRes)->getTitle().EOL;
67-
}
68-
}
69-
}
70-
}
40+
echo 'Task :'.$item->getName().EOL;
41+
echo ' >> Duration :'.$item->getDuration().EOL;
42+
echo ' >> StartDate :'.$item->getStartDate().EOL;
43+
echo ' >> EndDate :'.$item->getEndDate().EOL;
44+
echo ' >> Progress :'.$item->getProgress().EOL;
45+
echo ' >> Resources :'.EOL;
46+
$oTaskResources = $item->getResources();
47+
if(!empty($oTaskResources)){
48+
foreach ($oTaskResources as $itemRes){
49+
echo ' >>>> Resource :'.$objPHPProject->getResource($itemRes)->getTitle().EOL;
50+
}
51+
}
52+
53+
echo ' >> SubTasks :'.EOL;
54+
$oSubTasks = $item->getTasks();
55+
if(!empty($oSubTasks)){
56+
foreach ($oSubTasks as $itemSub){
57+
echo ' >>>> Task :'.$itemSub->getName().EOL;
58+
echo ' >>>>>> Duration :'.$itemSub->getDuration().EOL;
59+
echo ' >>>>>> StartDate :'.$itemSub->getStartDate().EOL;
60+
echo ' >>>>>> EndDate :'.$itemSub->getEndDate().EOL;
61+
echo ' >>>>>> Progress :'.$itemSub->getProgress().EOL;
62+
echo ' >>>>>> Resources :'.EOL;
63+
$oTaskResources = $itemSub->getResources();
64+
if(!empty($oTaskResources)){
65+
foreach ($oTaskResources as $itemRes){
66+
echo ' >>>>>>>> Resource :'.$objPHPProject->getResource($itemRes)->getTitle().EOL;
67+
}
68+
}
69+
}
70+
}
7171
}
7272
echo EOL;
7373

7474
// Echo done
7575
echo date('H:i:s') . ' Done reading file.'.EOL;
7676

7777
if (!CLI) {
78-
include_once 'Sample_Footer.php';
78+
include_once 'Sample_Footer.php';
7979
}

samples/Sample_02_ReadMSProjectExchange.php

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use PhpOffice\PhpProject\PHPProject;
66
use PhpOffice\PhpProject\IOFactory;
7-
7+
88
// Create new PHPProject object
99
echo date('H:i:s') . ' Create new PHPProject object'.EOL;
1010
$objReader = IOFactory::createReader('MSProjectExchange');
@@ -29,51 +29,51 @@
2929
echo date('H:i:s') . ' Get ressources'.EOL;
3030
$oResources = $objPHPProject->getAllResources();
3131
foreach ($oResources as $item){
32-
echo 'Resource :'.$item->getTitle().EOL;
32+
echo 'Resource :'.$item->getTitle().EOL;
3333
}
3434
echo EOL;
3535

3636
// Tasks
3737
echo date('H:i:s') . ' Get tasks'.EOL;
3838
$oTasks = $objPHPProject->getAllTasks();
3939
foreach ($oTasks as $item){
40-
echo 'Task :'.$item->getName().EOL;
41-
echo ' >> Duration :'.$item->getDuration().EOL;
42-
echo ' >> StartDate :'.$item->getStartDate().EOL;
43-
echo ' >> EndDate :'.$item->getEndDate().EOL;
44-
echo ' >> Progress :'.$item->getProgress().EOL;
45-
echo ' >> Resources :'.EOL;
46-
$oTaskResources = $item->getResources();
47-
if(!empty($oTaskResources)){
48-
foreach ($oTaskResources as $itemRes){
49-
echo ' >>>> Resource :'.$objPHPProject->getResource($itemRes)->getTitle().EOL;
50-
}
51-
}
52-
53-
echo ' >> SubTasks :'.EOL;
54-
$oSubTasks = $item->getTasks();
55-
if(!empty($oSubTasks)){
56-
foreach ($oSubTasks as $itemSub){
57-
echo ' >>>> Task :'.$itemSub->getName().EOL;
58-
echo ' >>>>>> Duration :'.$itemSub->getDuration().EOL;
59-
echo ' >>>>>> StartDate :'.$itemSub->getStartDate().EOL;
60-
echo ' >>>>>> EndDate :'.$itemSub->getEndDate().EOL;
61-
echo ' >>>>>> Progress :'.$itemSub->getProgress().EOL;
62-
echo ' >>>>>> Resources :'.EOL;
63-
$oTaskResources = $itemSub->getResources();
64-
if(!empty($oTaskResources)){
65-
foreach ($oTaskResources as $itemRes){
66-
echo ' >>>>>>>> Resource :'.$objPHPProject->getResource($itemRes)->getTitle().EOL;
67-
}
68-
}
69-
}
70-
}
40+
echo 'Task :'.$item->getName().EOL;
41+
echo ' >> Duration :'.$item->getDuration().EOL;
42+
echo ' >> StartDate :'.$item->getStartDate().EOL;
43+
echo ' >> EndDate :'.$item->getEndDate().EOL;
44+
echo ' >> Progress :'.$item->getProgress().EOL;
45+
echo ' >> Resources :'.EOL;
46+
$oTaskResources = $item->getResources();
47+
if(!empty($oTaskResources)){
48+
foreach ($oTaskResources as $itemRes){
49+
echo ' >>>> Resource :'.$objPHPProject->getResource($itemRes)->getTitle().EOL;
50+
}
51+
}
52+
53+
echo ' >> SubTasks :'.EOL;
54+
$oSubTasks = $item->getTasks();
55+
if(!empty($oSubTasks)){
56+
foreach ($oSubTasks as $itemSub){
57+
echo ' >>>> Task :'.$itemSub->getName().EOL;
58+
echo ' >>>>>> Duration :'.$itemSub->getDuration().EOL;
59+
echo ' >>>>>> StartDate :'.$itemSub->getStartDate().EOL;
60+
echo ' >>>>>> EndDate :'.$itemSub->getEndDate().EOL;
61+
echo ' >>>>>> Progress :'.$itemSub->getProgress().EOL;
62+
echo ' >>>>>> Resources :'.EOL;
63+
$oTaskResources = $itemSub->getResources();
64+
if(!empty($oTaskResources)){
65+
foreach ($oTaskResources as $itemRes){
66+
echo ' >>>>>>>> Resource :'.$objPHPProject->getResource($itemRes)->getTitle().EOL;
67+
}
68+
}
69+
}
70+
}
7171
}
7272
echo EOL;
7373

7474
// Echo done
7575
echo date('H:i:s') . ' Done reading file.'.EOL;
7676

7777
if (!CLI) {
78-
include_once 'Sample_Footer.php';
78+
include_once 'Sample_Footer.php';
7979
}

samples/Sample_Header.php

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
// Return to the caller script when runs by CLI
2121
if (CLI) {
22-
return;
22+
return;
2323
}
2424

2525
// Set titles and names
@@ -31,13 +31,13 @@
3131
// Populate samples
3232
$files = '';
3333
if ($handle = opendir('.')) {
34-
while (false !== ($file = readdir($handle))) {
35-
if (preg_match('/^Sample_\d+_/', $file)) {
36-
$name = str_replace('_', ' ', preg_replace('/(Sample_|\.php)/', '', $file));
37-
$files .= "<li><a href='{$file}'>{$name}</a></li>";
38-
}
39-
}
40-
closedir($handle);
34+
while (false !== ($file = readdir($handle))) {
35+
if (preg_match('/^Sample_\d+_/', $file)) {
36+
$name = str_replace('_', ' ', preg_replace('/(Sample_|\.php)/', '', $file));
37+
$files .= "<li><a href='{$file}'>{$name}</a></li>";
38+
}
39+
}
40+
closedir($handle);
4141
}
4242

4343
/**
@@ -49,24 +49,24 @@
4949
*/
5050
function write($phpPowerPoint, $filename, $writers)
5151
{
52-
$result = '';
53-
54-
// Write documents
55-
foreach ($writers as $writer => $extension) {
56-
$result .= date('H:i:s') . " Write to {$writer} format";
57-
if (!is_null($extension)) {
58-
$xmlWriter = IOFactory::createWriter($phpPowerPoint, $writer);
59-
$xmlWriter->save(__DIR__ . "/{$filename}.{$extension}");
60-
rename(__DIR__ . "/{$filename}.{$extension}", __DIR__ . "/results/{$filename}.{$extension}");
61-
} else {
62-
$result .= ' ... NOT DONE!';
63-
}
64-
$result .= EOL;
65-
}
52+
$result = '';
53+
54+
// Write documents
55+
foreach ($writers as $writer => $extension) {
56+
$result .= date('H:i:s') . " Write to {$writer} format";
57+
if (!is_null($extension)) {
58+
$xmlWriter = IOFactory::createWriter($phpPowerPoint, $writer);
59+
$xmlWriter->save(__DIR__ . "/{$filename}.{$extension}");
60+
rename(__DIR__ . "/{$filename}.{$extension}", __DIR__ . "/results/{$filename}.{$extension}");
61+
} else {
62+
$result .= ' ... NOT DONE!';
63+
}
64+
$result .= EOL;
65+
}
6666

67-
$result .= getEndingNotes($writers);
67+
$result .= getEndingNotes($writers);
6868

69-
return $result;
69+
return $result;
7070
}
7171

7272
/**
@@ -76,35 +76,35 @@ function write($phpPowerPoint, $filename, $writers)
7676
*/
7777
function getEndingNotes($writers)
7878
{
79-
$result = '';
79+
$result = '';
8080

81-
// Do not show execution time for index
82-
if (!IS_INDEX) {
83-
$result .= date('H:i:s') . " Done writing file(s)" . EOL;
84-
$result .= date('H:i:s') . " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB" . EOL;
85-
}
81+
// Do not show execution time for index
82+
if (!IS_INDEX) {
83+
$result .= date('H:i:s') . " Done writing file(s)" . EOL;
84+
$result .= date('H:i:s') . " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB" . EOL;
85+
}
8686

87-
// Return
88-
if (CLI) {
89-
$result .= 'The results are stored in the "results" subdirectory.' . EOL;
90-
} else {
91-
if (!IS_INDEX) {
92-
$types = array_values($writers);
93-
$result .= '<p>&nbsp;</p>';
94-
$result .= '<p>Results: ';
95-
foreach ($types as $type) {
96-
if (!is_null($type)) {
97-
$resultFile = 'results/' . SCRIPT_FILENAME . '.' . $type;
98-
if (file_exists($resultFile)) {
99-
$result .= "<a href='{$resultFile}' class='btn btn-primary'>{$type}</a> ";
100-
}
101-
}
102-
}
103-
$result .= '</p>';
104-
}
105-
}
87+
// Return
88+
if (CLI) {
89+
$result .= 'The results are stored in the "results" subdirectory.' . EOL;
90+
} else {
91+
if (!IS_INDEX) {
92+
$types = array_values($writers);
93+
$result .= '<p>&nbsp;</p>';
94+
$result .= '<p>Results: ';
95+
foreach ($types as $type) {
96+
if (!is_null($type)) {
97+
$resultFile = 'results/' . SCRIPT_FILENAME . '.' . $type;
98+
if (file_exists($resultFile)) {
99+
$result .= "<a href='{$resultFile}' class='btn btn-primary'>{$type}</a> ";
100+
}
101+
}
102+
}
103+
$result .= '</p>';
104+
}
105+
}
106106

107-
return $result;
107+
return $result;
108108
}
109109

110110
?>

src/PhpProject/Autoloader.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ public static function autoload($class)
4646
if (0 === strncmp(self::NAMESPACE_PREFIX, $class, $prefixLength)) {
4747
$file = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, $prefixLength));
4848
$file = realpath(__DIR__ . (empty($file) ? '' : DIRECTORY_SEPARATOR) . $file . '.php');
49+
// @codeCoverageIgnoreStart
4950
if (file_exists($file)) {
50-
/** @noinspection PhpIncludeInspection Dynamic includes */
5151
require_once $file;
5252
}
53+
// @codeCoverageIgnoreEnd
5354
}
5455
}
5556
}

src/PhpProject/DocumentProperties.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,7 @@ public function getCustomPropertyType($propertyName)
456456
public function setCustomProperty($propertyName, $propertyValue = '', $propertyType = null)
457457
{
458458
if (($propertyType === null) || (!in_array($propertyType, array(self::PROPERTY_TYPE_INTEGER, self::PROPERTY_TYPE_FLOAT, self::PROPERTY_TYPE_STRING, self::PROPERTY_TYPE_DATE, self::PROPERTY_TYPE_BOOLEAN)))) {
459-
if ($propertyValue === null) {
460-
$propertyType = self::PROPERTY_TYPE_STRING;
461-
} elseif (is_float($propertyValue)) {
459+
if (is_float($propertyValue)) {
462460
$propertyType = self::PROPERTY_TYPE_FLOAT;
463461
} elseif (is_int($propertyValue)) {
464462
$propertyType = self::PROPERTY_TYPE_INTEGER;

0 commit comments

Comments
 (0)