public function testScalar()
 {
     $s = new \PerrysLambda\ScalarProperty("Zähn € zahme Ziegen zögen zwei Zentner Zücker zum Zoö!", 'UTF-8');
     $this->assertSame(true, $s->startsWith("Zä"));
     $this->assertSame(false, $s->startsWith("zä"));
     $this->assertSame(true, $s->startsWithI("zä"));
     $this->assertSame(true, $s->endsWith(' Zoö!'));
     $this->assertSame(false, $s->endsWith(' zoö!'));
     $this->assertSame(true, $s->endsWithI(' zoö!'));
     $this->assertSame(54, $s->length());
     $this->assertSame(3, count($s->split('ö')));
     $this->assertSame(' Zoö!', $s->substr(-5));
     $this->assertSame(1, $s->indexOf('ä'));
     $this->assertSame(-1, $s->indexOf('Ä'));
     $this->assertSame(1, $s->indexOfI('Ä'));
     $this->assertSame(53, $s->lastIndexOf('!'));
     $this->assertSame(50, $s->lastIndexOfI('zoö!'));
     $this->assertSame(false, $s->contains('asdf'));
     $this->assertSame(true, $s->contains('zwei'));
     $this->assertSame(false, $s->contains('ZWEI'));
     $this->assertSame(true, $s->containsI('ZWEI'));
     $integer = new PerrysLambda\ScalarProperty('4211');
     $this->assertSame(4211, $integer->toInt());
     $this->assertSame(4211, $integer->toNumeric());
     $float = new PerrysLambda\ScalarProperty('50.4');
     $realfloat = new PerrysLambda\ScalarProperty(50.4);
     $null = new PerrysLambda\ScalarProperty(null);
     $bool = new PerrysLambda\ScalarProperty(true);
     $this->assertSame(true, $float->isNumeric());
     $this->assertSame(true, $float->isString());
     $this->assertSame(50.4, $float->toNumeric());
     $this->assertSame(50.4, $float->toFloat());
     $this->assertSame(false, $float->isFloat());
     $this->assertSame(false, $float->isInt());
     $this->assertSame(true, $realfloat->isFloat());
     $this->assertSame(true, $realfloat->isNumeric());
     $this->assertSame(false, $realfloat->isInt());
     $this->assertSame(false, $realfloat->isString());
     $this->assertSame(false, $realfloat->isNull());
     $this->assertSame(true, $null->isNull());
     $this->assertSame(false, $null->isBool());
     $this->assertSame(true, $bool->isBool());
     $this->assertSame(true, $float->toBool());
     $string = new PerrysLambda\ScalarProperty(50.3);
     $this->assertSame('50.3', $string->toString());
 }
Exemple #2
0
<?php

/**
 * Dieses Script einfach in einer CLI ausführen
 * Ein Webserver ist nicht notwendig.
 *
 * Dieses Script demonstriert den Scalar Typ
 */
include __DIR__ . "/examples-utils.php";
$s = new \PerrysLambda\ScalarProperty("Zähn € zahme Ziegen zögen zwei Zentner Zücker zum Zoö!");
echo "\n";
L::line("Begin");
echo "\n";
L::line($s->toString());
echo "\n";
L::line("Length:", $s->length());
L::line("Begin with \"Zä\":", L::b($s->startsWith("Zä")));
L::line("Begin with \"Ze\":", L::b($s->startsWith("Ze")));
L::line("Ends with \"Zoö!\":", L::b($s->endsWith("Zoö!")));
L::line("Ends with \"Zoo!\":", L::b($s->endsWith("Zoo!")));
L::line("Last 4 chars:", $s->substr(-4));
L::line("Contains \"zögen\":", L::b($s->contains('zögen')));
L::line("Contains \"zogen\":", L::b($s->contains('zogen')));
L::line("Index of \"ö\":", $s->indexOf('ö'));
L::line("Last index of \"ö\":", $s->lastIndexOf('ö'));
echo "\n";