Permalink
Browse files

Create rtut.sh

  • Loading branch information...
1 parent 85103b8 commit ae86dd8f203dec4adac38d93e687412cb799a9e0 @jaytaph committed Feb 1, 2014
Showing with 64 additions and 0 deletions.
  1. +64 −0 rtut.sh
View
64 rtut.sh
@@ -0,0 +1,64 @@
+#!/bin/bash
+#
+# Copyright (c) 2014, Joshua Thijssen
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of the <organization> nor the
+# names of its contributors may be used to endorse or promote products
+# derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+#
+# Usage: rtut.sh <testdirectory>
+#
+# Real-time PHPUnit tester. Leave this script running inside a bash shell to get
+# instant feedback whenever a file or unit-test file changes.
+#
+# Use with the directory where your unit-tests are stored. If <testdirectory> is not set, it will
+# use ./tests as default argument.
+#
+
+TESTDIR=${1:-"./tests"}
+
+inotifywait -m . -q -r --format "%w%f" -e moved_to,create,modify | while read line
+do
+ # Check if our file ends with .php
+ REGEX=".php$"
+ if [[ ! $line =~ $REGEX ]] ; then
+ continue;
+ fi
+
+
+ REGEX="^${TESTDIR}/"
+ if [[ "$line" =~ $REGEX ]] ; then
+ # File is inside test dir, do not convert
+ TESTFILE="${line}"
+ else
+ # Convert normal file to a testfile
+ TESTFILE=`echo "${TESTDIR}/$line" | sed -e 's/.php$/Test.php/'`
+ fi
+
+ # Test file is not found
+ if [ ! -f "${TESTFILE}" ] ; then
+ continue;
+ fi
+
+ phpunit ${TESTFILE}
+done

0 comments on commit ae86dd8

Please sign in to comment.