Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 5f3dba79db4d6e4f64e6dba7f9b9ad1315f7d9b1 mparaiso committed Sep 26, 2012
Showing with 154 additions and 0 deletions.
  1. +74 −0 String/String.php
  2. +24 −0 phpunit.xml
  3. +53 −0 tests/String/StringTest.php
  4. +3 −0 tests/bootstrap.php
@@ -0,0 +1,74 @@
+<?php
+
+namespace String{
+ class String{
+
+ protected $value;
+
+
+ function __construct($value=null){
+ $this->value = $value;
+ }
+
+ function _concat($value){
+ $value= (string)$value;
+ return $this->value.$value;
+ }
+
+ function _indexOf($searchValue,$start=0){
+ $result = strpos($this->value,$searchValue);
+ if($result>=0 && $result!==false){
+ return $result;
+ }else{
+ return -1;
+ }
+ }
+
+
+ function __toString(){
+ return $this->value;
+ }
+
+ public function __call($name,$arguments){
+ $method = "_".$name;
+ if(method_exists($this, $method)){
+ return call_user_func_array(array($this,$method),$arguments);
+ }
+ }
+
+ public static function __callStatic($name,$arguments){
+ $method = "_".$name;
+ // vérifier si une méthode existe pour une methode statique
+ $string = new String();
+ if (method_exists($string, $method)){
+ // first argument is a string
+ $string = new String($arguments[0]);
+ $rest = array_slice($arguments, 1);
+ return call_user_func_array(array($string,$method), $rest);
+ }
+ throw new Exception("The method $method doesnt exists", 1);
+
+ }
+
+ function __get($attr){
+ $method = "get".ucwords($attr);
+ if(method_exists($this,$method)){
+ return $this->$method();
+ }
+ if(property_exists($this,$attr)){
+ return $this->$attr;
+ }
+ }
+
+ function __set($attr,$value){
+ $method = "set".ucwords($attr);
+ if(method_exists($this, $method)){
+ return $this->$method($value);
+ }
+ if(property_exists($this,$attr)){
+ $this->$attr = $value;
+ return $this->$attr;
+ }
+ }
+ }
+}
@@ -0,0 +1,24 @@
+<?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="true"
+ bootstrap="./tests/bootstrap.php"
+>
+ <testsuites>
+ <testsuite name="Canvas Test Suite">
+ <directory>./tests</directory>
+ </testsuite>
+ </testsuites>
+ <filter>
+ <whitelist>
+ <directory>./src</directory>
+ </whitelist>
+ </filter>
+</phpunit>
@@ -0,0 +1,53 @@
+<?php
+namespace String{
+
+ /**
+ * fixtures for String\String class
+ */
+ class StringTest extends \PHPUnit_Framework_TestCase{
+ /**
+ * String\String
+ */
+ protected $string;
+
+ protected $value;
+
+
+ public function setUp(){
+ $this->value = "strings";
+ $this->string = new String($this->value);
+ }
+
+ function testConstruct(){
+ $this->assertEquals($this->value,$this->string->value);
+ }
+
+ function testIndexOf(){
+ $this->assertEquals(-1,$this->string->indexOf("x"));
+ $this->assertEquals(-1,String::indexOf($this->value,"x"));
+
+ $this->assertEquals(0,$this->string->indexOf("s"));
+ $this->assertEquals(0,String::indexOf($this->value,'s'));
+ }
+
+ function testConcat(){
+ $this->assertEquals("stringsplus",$this->string->concat("plus"));
+ $this->assertEquals("stringsplus",String::concat("strings","plus"));
+
+ $this->assertEquals("strings1",$this->string->concat(1));
+ $this->assertEquals("strings1",String::concat($this->value,1));
+ }
+
+ function testToString(){
+ $this->assertEquals("strings",$this->string."");
+ }
+
+ function testNew(){
+
+ }
+
+ function tearDown(){
+ }
+
+ }
+}
@@ -0,0 +1,3 @@
+<?php
+
+require dirname(__DIR__)."/String/String.php";

0 comments on commit 5f3dba7

Please sign in to comment.