Commits

hideki nara committed 1f8ba00

Stagehand\Greeting works

Comments (0)

Files changed (8)

+test export-ignore
+phpunit.xml.dist export-ignore
+vendor
+composer.phar
+composer.lock
+phpunit.xml
+
 # This is a sample php library 
+
+# Install phpunit
+
+install Composer:
+
+
+    $ curl -s http://getcomposer.org/installer | php                                                                    
+
+    #!/usr/bin/env php
+    All settings correct for using Composer
+    Downloading...
+    
+    Composer successfully installed to: /home/hdknr/php/stagehand/composer.phar
+    Use it: php composer.phar
+
+edit composer.json:
+
+    {
+        "require-dev": {
+            "phpunit/phpunit": "3.7.*"
+        },
+        "autoload": {
+            "psr-0": { "": "lib/" }
+        }
+    }
+
+install:
+
+    $ php composer.phar install
+
+    Loading composer repositories with package information
+    Installing dependencies (including require-dev)
+      - Installing symfony/yaml (v2.4.0)
+        Loading from cache
+    
+      - Installing phpunit/php-text-template (1.1.4)
+        Loading from cache
+    
+      - Installing phpunit/phpunit-mock-objects (1.2.3)
+        Loading from cache
+    
+      - Installing phpunit/php-timer (1.0.5)
+        Loading from cache
+    
+      - Installing phpunit/php-token-stream (1.2.1)
+        Loading from cache
+    
+      - Installing phpunit/php-file-iterator (1.3.4)
+        Loading from cache
+    
+      - Installing phpunit/php-code-coverage (1.2.13)
+        Loading from cache
+    
+      - Installing phpunit/phpunit (3.7.28)
+        Loading from cache
+    
+    phpunit/php-code-coverage suggests installing ext-xdebug (>=2.0.5)
+    phpunit/phpunit suggests installing phpunit/php-invoker (>=1.1.0,<1.2.0)
+    Writing lock file
+    Generating autoload files
+
+phpunit.xml:
+
+
+    $ cp phpunit.xml.dist  phpunit.xml
+    $ vi phpunit.xml
+
+run:
+
+    $ vendor/phpunit/phpunit/phpunit.php 
+
+    PHPUnit 3.7.28 by Sebastian Bergmann.
+    
+    Configuration read from /home/hdknr/php/stagehand/phpunit.xml
+    
+    Time: 32 ms, Memory: 2.50Mb
+    
+    OK (1 test, 1 assertion)
+{
+    "require-dev": {
+        "phpunit/phpunit": "3.7.*"
+    },
+    "autoload": {
+        "psr-0": { "": "lib/" }
+    }
+}

lib/Stagehand/Greeting.php

+<?php
+namespace Stagehand;
+
+class Greeting
+{
+    protected
+        $hello;
+
+    function __construct( $hello='Hello')
+    {
+        $this->hello = $hello;
+    } 
+    public function sayHello()
+    {
+        return $this->hello; 
+    }
+}
+<?xml version="1.0" encoding="UTF-8"?>
+
+<phpunit backupGlobals="false"
+         backupStaticAttributes="false"
+         colors="true"
+         convertErrorsToExceptions="true"
+         convertNoticesToExceptions="true"
+         convertWarningsToExceptions="true"
+         processIsolation="false"
+         stopOnFailure="false"
+         syntaxCheck="false"
+         bootstrap="./test/bootstrap.php"
+>
+    <testsuites>
+        <testsuite name="Stagehand Tests">
+            <directory>./test/Stagehand/</directory>
+        </testsuite>
+    </testsuites>
+
+    <filter>
+        <whitelist>
+            <directory suffix=".php">./lib/</directory>
+        </whitelist>
+    </filter>
+</phpunit>

test/Stagehand/SimpleTest.php

+<?php
+
+use Stagehand\Greeting;
+
+class SimpleTest extends PHPUnit_Framework_TestCase
+{
+    public function testHello() {
+        $msg="Konnichiwa";
+        $greeting = new Greeting( $msg );
+        $this->assertEquals($msg, $greeting->sayHello());
+    }
+}

test/bootstrap.php

+<?php
+
+require_once __DIR__.'/../vendor/autoload.php';