Adding Splitter Tests
authorMaxime Bourget <bmx007@gmail.com>
Fri, 7 Jun 2013 22:20:15 +0000 (23:20 +0100)
committerMaxime Bourget <bmx007@gmail.com>
Fri, 7 Jun 2013 22:20:15 +0000 (23:20 +0100)
includes/splitter.inc
tests/helper.php [new file with mode: 0644]
tests/splitTest.php
tests/testSplitter.php [new file with mode: 0644]

index a9f47b938f596c23bf22c31054b3ead64df8b1e8..c3aff0ad894d1cba21c04e3db8d1a0e13f7b0fc2 100644 (file)
@@ -22,12 +22,13 @@ class Splitter {
        public $quantity_max;
 
        public function __construct(array $data) {
+               $this->details_id = array();
                foreach($data['detail'] as $detail_id => $detail) {
                        array_push($this->details_id, $detail_id);
                }
-               $start_date = $data['start_date'];
-               $end_date = $data['end_date'];
-               $days = date_diff2($start_date, $end_date, 'd');
+               $this->start_date = $data['start_date'];
+               $this->end_date = $data['end_date'];
+               $this->days = date_diff2($this->end_date, $this->start_date, 'd');
        }
 
        protected function loadDetail($detail_id) {
@@ -46,6 +47,10 @@ class Splitter {
                }
        }
 
+       public function days() {
+               return $this->days;
+       }
+
 
        
        /* This function splits on order detail in bits of a specified size.
diff --git a/tests/helper.php b/tests/helper.php
new file mode 100644 (file)
index 0000000..16be518
--- /dev/null
@@ -0,0 +1,15 @@
+<?php
+$path_to_root = '../../';
+
+/* Stubbing undefined function */
+global $dateformats, $dateseps;
+       $dateformats    = array("MMDDYYYY", "DDMMYYYY", "YYYYMMDD","MmmDDYYYY", "DDMmmYYYY", "YYYYMmmDD");
+       $dateseps               = array("/", ".", "-", " ");
+function user_date_format() {
+       return 2; // YYYMMDD
+}
+
+function user_date_sep() {
+       return 0;
+}
+?>
index 693521a88de69bc8f5219b859ac4158f5afb9467..77a64405a9b71ffcfc361315f0e09e86cc39856f 100644 (file)
@@ -1,19 +1,7 @@
 <?php
-global $path_to_root;
-$path_to_root = '../../';
+require_once('tests/helper.php');
 require_once('includes/splitter.inc');
 
-/* Stubbing undefined function */
-global $dateformats, $dateseps;
-       $dateformats    = array("MMDDYYYY", "DDMMYYYY", "YYYYMMDD","MmmDDYYYY", "DDMmmYYYY", "YYYYMmmDD");
-       $dateseps               = array("/", ".", "-", " ");
-function user_date_format() {
-       return 2; // YYYMMDD
-}
-
-function user_date_sep() {
-       return 0;
-}
 
 class splitTest extends PHPUnit_Framework_TestCase {
        public function testConstructor() {
diff --git a/tests/testSplitter.php b/tests/testSplitter.php
new file mode 100644 (file)
index 0000000..fa42f7a
--- /dev/null
@@ -0,0 +1,19 @@
+<?php
+require_once('tests/helper.php');
+require_once('includes/splitter.inc');
+class splitterTest extends PHPUnit_Framework_TestCase {
+       public function testConstruct() {
+               $start_date = '2013/05/01';
+               $end_date = '2013/05/31';
+               $details = array('1' => 'details 1', '2' => 'details', '3' => 'd3');
+
+               $splitter = new Splitter(array('detail' => $details
+                       , 'start_date'=> $start_date
+                       , 'end_date' => $end_date));
+               $this->assertEquals($start_date, $splitter->start_date);
+               $this->assertEquals($end_date, $splitter->end_date);
+               $this->assertEquals($splitter->days(), 30);
+
+       }
+}
+?>