Commits

lornajane committed c25e9b7 Draft

adding a simple model, phpunit config and tests

Comments (0)

Files changed (4)

sample-code/build.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<project name="example" basedir="." default="deploy">
+        <property name="builddir" value="./build" />
+        <property name="appdir" value="./build/code" />
+        <property name="repo" value="http://svn.valinor.local/lorna-test" />
+        <tstamp>
+            <format property="date" pattern="%Y%m%d-%H%M" />
+        </tstamp>
+
+        <target name="deploy" depends="clean, prepare, export, putlive" />
+
+        <target name="export">
+            <exec command="svn export ${repo} ${appdir}/${date}" />
+        </target>
+
+        <target name="putlive">
+            <exec command="scp -r ${appdir}/${date} lorna@rivendell.local:testing/ >${builddir}/logs/scp.log" />
+        </target>
+
+        <target name="clean">
+                <delete dir="${builddir}" />
+        </target>
+
+        <target name="prepare">
+                <mkdir dir="${builddir}" />
+                <mkdir dir="${builddir}/logs" />
+        </target>
+</project>
+

sample-code/src/models/MathUtilModel.php

+<?php
+
+class MathUtilModel {
+    public function addNumbers($a, $b) {
+        if(!is_numeric($a) || !is_numeric($b)) {
+            throw new UnexpectedValueException('addNumbers expects numeric values only');
+        }
+        return $a + $b;
+    }
+}

sample-code/tests/models/MathUtilModelTest.php

+<?php
+
+require_once '../src/models/MathUtilModel.php';
+
+class MathUtilModelTest extends PHPUnit_Framework_TestCase {
+    public function testAddNumbersWithNumbers() {
+        $util = new MathUtilModel();
+        $result = $util->addNumbers(3,5);
+        $this->assertEquals(8, $result);
+    }
+}

sample-code/tests/phpunit.xml

+<phpunit>
+    <testsuites>
+      <testsuite name="models">
+        <directory>models</directory>
+      </testsuite>
+    </testsuites>
+</phpunit>