Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don’t worry, you can still create the pull request.
  • 4 commits
  • 16 files changed
  • 0 commit comments
  • 1 contributor
Showing with 976 additions and 3 deletions.
  1. +4 −3 .gitignore
  2. +2 −0 TDDMicroExercises.YoursSolutions/PHP-frubini/.gitignore
  3. +18 −0 TDDMicroExercises.YoursSolutions/PHP-frubini/composer.json
  4. +477 −0 TDDMicroExercises.YoursSolutions/PHP-frubini/composer.lock
  5. +93 −0 ...xercises.YoursSolutions/PHP-frubini/src/TDDMicroExercises/PHP/TelemetrySystem/TelemetryClient.php
  6. +49 −0 ...rsSolutions/PHP-frubini/src/TDDMicroExercises/PHP/TelemetrySystem/TelemetryDiagnosticControls.php
  7. +37 −0 ...cises.YoursSolutions/PHP-frubini/src/TDDMicroExercises/PHP/TirePressureMonitoringSystem/Alarm.php
  8. +21 −0 ...ises.YoursSolutions/PHP-frubini/src/TDDMicroExercises/PHP/TirePressureMonitoringSystem/Sensor.php
  9. +15 −0 ...ises.YoursSolutions/PHP-frubini/src/TDDMicroExercises/PHP/TurnTicketDispenser/TicketDispenser.php
  10. +13 −0 ...s.YoursSolutions/PHP-frubini/src/TDDMicroExercises/PHP/TurnTicketDispenser/TurnNumberSequence.php
  11. +18 −0 ...Exercises.YoursSolutions/PHP-frubini/src/TDDMicroExercises/PHP/TurnTicketDispenser/TurnTicket.php
  12. +52 −0 ...ubini/src/TDDMicroExercises/PHP/UnicodeFileToHtmlTextConverter/UnicodeFileToHtmlTextConverter.php
  13. +97 −0 ....YoursSolutions/PHP-frubini/test/TDDMicroExercises/PHP/TirePressureMonitoringSystem/AlarmTest.php
  14. +70 −0 .../test/TDDMicroExercises/PHP/UnicodeFileToHtmlTextConverter/UnicodeFileToHtmlTextConverterTest.php
  15. +8 −0 TDDMicroExercises.YoursSolutions/PHP-frubini/test/bootstrap.php
  16. +2 −0 TDDMicroExercises.YoursSolutions/PHP-frubini/test/phpunit.xml
View
7 .gitignore
@@ -2,6 +2,7 @@ bin/
obj/
_ReSharper*/
*.suo
-*.user
-.DS_Store
-*.pyc
+*.user
+.DS_Store
+*.pyc
+.idea/
View
2 TDDMicroExercises.YoursSolutions/PHP-frubini/.gitignore
@@ -0,0 +1,2 @@
+composer.phar
+vendor/
View
18 TDDMicroExercises.YoursSolutions/PHP-frubini/composer.json
@@ -0,0 +1,18 @@
+{
+ "name": "vendor_name/package_name",
+ "description": "description_text",
+ "minimum-stability": "stable",
+ "authors": [
+ {
+ "name": "Federico Rubini",
+ "email": "email@example.com"
+ }
+ ],
+ "require": {
+ "phpunit/phpunit": "3.7.*",
+ "mikey179/vfsStream": "dev-master"
+ },
+ "autoload": {
+ "psr-0": {"TDDMicroExercises": "src/"}
+ }
+}
View
477 TDDMicroExercises.YoursSolutions/PHP-frubini/composer.lock
@@ -0,0 +1,477 @@
+{
+ "_readme": [
+ "This file locks the dependencies of your project to a known state",
+ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
+ ],
+ "hash": "30165c39922838fac2526383d64f802b",
+ "packages": [
+ {
+ "name": "mikey179/vfsStream",
+ "version": "dev-master",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/mikey179/vfsStream.git",
+ "reference": "6cc4209e5f1ef334ebb4674686a491f415dd71ac"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/mikey179/vfsStream/zipball/6cc4209e5f1ef334ebb4674686a491f415dd71ac",
+ "reference": "6cc4209e5f1ef334ebb4674686a491f415dd71ac",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.0"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "~3.7"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.3.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-0": {
+ "org\\bovigo\\vfs\\": "src/main/php"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD"
+ ],
+ "homepage": "http://vfs.bovigo.org/",
+ "time": "2013-10-29 22:28:40"
+ },
+ {
+ "name": "phpunit/php-code-coverage",
+ "version": "1.2.13",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/php-code-coverage.git",
+ "reference": "466e7cd2554b4e264c9e3f31216d25ac0e5f3d94"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/466e7cd2554b4e264c9e3f31216d25ac0e5f3d94",
+ "reference": "466e7cd2554b4e264c9e3f31216d25ac0e5f3d94",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3",
+ "phpunit/php-file-iterator": ">=1.3.0@stable",
+ "phpunit/php-text-template": ">=1.1.1@stable",
+ "phpunit/php-token-stream": ">=1.1.3@stable"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "3.7.*@dev"
+ },
+ "suggest": {
+ "ext-dom": "*",
+ "ext-xdebug": ">=2.0.5"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.2.x-dev"
+ }
+ },
+ "autoload": {
+ "classmap": [
+ "PHP/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "include-path": [
+ ""
+ ],
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sb@sebastian-bergmann.de",
+ "role": "lead"
+ }
+ ],
+ "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.",
+ "homepage": "https://github.com/sebastianbergmann/php-code-coverage",
+ "keywords": [
+ "coverage",
+ "testing",
+ "xunit"
+ ],
+ "time": "2013-09-10 08:14:32"
+ },
+ {
+ "name": "phpunit/php-file-iterator",
+ "version": "1.3.4",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/php-file-iterator.git",
+ "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/acd690379117b042d1c8af1fafd61bde001bf6bb",
+ "reference": "acd690379117b042d1c8af1fafd61bde001bf6bb",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "type": "library",
+ "autoload": {
+ "classmap": [
+ "File/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "include-path": [
+ ""
+ ],
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sb@sebastian-bergmann.de",
+ "role": "lead"
+ }
+ ],
+ "description": "FilterIterator implementation that filters files based on a list of suffixes.",
+ "homepage": "https://github.com/sebastianbergmann/php-file-iterator/",
+ "keywords": [
+ "filesystem",
+ "iterator"
+ ],
+ "time": "2013-10-10 15:34:57"
+ },
+ {
+ "name": "phpunit/php-text-template",
+ "version": "1.1.4",
+ "source": {
+ "type": "git",
+ "url": "git://github.com/sebastianbergmann/php-text-template.git",
+ "reference": "1.1.4"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://github.com/sebastianbergmann/php-text-template/zipball/1.1.4",
+ "reference": "1.1.4",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "type": "library",
+ "autoload": {
+ "classmap": [
+ "Text/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "include-path": [
+ ""
+ ],
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sb@sebastian-bergmann.de",
+ "role": "lead"
+ }
+ ],
+ "description": "Simple template engine.",
+ "homepage": "https://github.com/sebastianbergmann/php-text-template/",
+ "keywords": [
+ "template"
+ ],
+ "time": "2012-10-31 11:15:28"
+ },
+ {
+ "name": "phpunit/php-timer",
+ "version": "1.0.5",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/php-timer.git",
+ "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/19689d4354b295ee3d8c54b4f42c3efb69cbc17c",
+ "reference": "19689d4354b295ee3d8c54b4f42c3efb69cbc17c",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "type": "library",
+ "autoload": {
+ "classmap": [
+ "PHP/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "include-path": [
+ ""
+ ],
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sb@sebastian-bergmann.de",
+ "role": "lead"
+ }
+ ],
+ "description": "Utility class for timing",
+ "homepage": "https://github.com/sebastianbergmann/php-timer/",
+ "keywords": [
+ "timer"
+ ],
+ "time": "2013-08-02 07:42:54"
+ },
+ {
+ "name": "phpunit/php-token-stream",
+ "version": "1.2.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/php-token-stream.git",
+ "reference": "5220af2a7929aa35cf663d97c89ad3d50cf5fa3e"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/5220af2a7929aa35cf663d97c89ad3d50cf5fa3e",
+ "reference": "5220af2a7929aa35cf663d97c89ad3d50cf5fa3e",
+ "shasum": ""
+ },
+ "require": {
+ "ext-tokenizer": "*",
+ "php": ">=5.3.3"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.2-dev"
+ }
+ },
+ "autoload": {
+ "classmap": [
+ "PHP/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "include-path": [
+ ""
+ ],
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sb@sebastian-bergmann.de",
+ "role": "lead"
+ }
+ ],
+ "description": "Wrapper around PHP's tokenizer extension.",
+ "homepage": "https://github.com/sebastianbergmann/php-token-stream/",
+ "keywords": [
+ "tokenizer"
+ ],
+ "time": "2013-09-13 04:58:23"
+ },
+ {
+ "name": "phpunit/phpunit",
+ "version": "3.7.28",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/sebastianbergmann/phpunit.git",
+ "reference": "3b97c8492bcafbabe6b6fbd2ab35f2f04d932a8d"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/3b97c8492bcafbabe6b6fbd2ab35f2f04d932a8d",
+ "reference": "3b97c8492bcafbabe6b6fbd2ab35f2f04d932a8d",
+ "shasum": ""
+ },
+ "require": {
+ "ext-dom": "*",
+ "ext-pcre": "*",
+ "ext-reflection": "*",
+ "ext-spl": "*",
+ "php": ">=5.3.3",
+ "phpunit/php-code-coverage": "~1.2.1",
+ "phpunit/php-file-iterator": ">=1.3.1",
+ "phpunit/php-text-template": ">=1.1.1",
+ "phpunit/php-timer": ">=1.0.4",
+ "phpunit/phpunit-mock-objects": "~1.2.0",
+ "symfony/yaml": "~2.0"
+ },
+ "require-dev": {
+ "pear-pear/pear": "1.9.4"
+ },
+ "suggest": {
+ "ext-json": "*",
+ "ext-simplexml": "*",
+ "ext-tokenizer": "*",
+ "phpunit/php-invoker": ">=1.1.0,<1.2.0"
+ },
+ "bin": [
+ "composer/bin/phpunit"
+ ],
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "3.7.x-dev"
+ }
+ },
+ "autoload": {
+ "classmap": [
+ "PHPUnit/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "include-path": [
+ "",
+ "../../symfony/yaml/"
+ ],
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sebastian@phpunit.de",
+ "role": "lead"
+ }
+ ],
+ "description": "The PHP Unit Testing framework.",
+ "homepage": "http://www.phpunit.de/",
+ "keywords": [
+ "phpunit",
+ "testing",
+ "xunit"
+ ],
+ "time": "2013-10-17 07:27:40"
+ },
+ {
+ "name": "phpunit/phpunit-mock-objects",
+ "version": "1.2.3",
+ "source": {
+ "type": "git",
+ "url": "git://github.com/sebastianbergmann/phpunit-mock-objects.git",
+ "reference": "1.2.3"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://github.com/sebastianbergmann/phpunit-mock-objects/archive/1.2.3.zip",
+ "reference": "1.2.3",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3",
+ "phpunit/php-text-template": ">=1.1.1@stable"
+ },
+ "suggest": {
+ "ext-soap": "*"
+ },
+ "type": "library",
+ "autoload": {
+ "classmap": [
+ "PHPUnit/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "include-path": [
+ ""
+ ],
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Sebastian Bergmann",
+ "email": "sb@sebastian-bergmann.de",
+ "role": "lead"
+ }
+ ],
+ "description": "Mock Object library for PHPUnit",
+ "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/",
+ "keywords": [
+ "mock",
+ "xunit"
+ ],
+ "time": "2013-01-13 10:24:48"
+ },
+ {
+ "name": "symfony/yaml",
+ "version": "v2.3.6",
+ "target-dir": "Symfony/Component/Yaml",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/Yaml.git",
+ "reference": "6bb881b948368482e1abf1a75c08bcf88a1c5fc3"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symfony/Yaml/zipball/6bb881b948368482e1abf1a75c08bcf88a1c5fc3",
+ "reference": "6bb881b948368482e1abf1a75c08bcf88a1c5fc3",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.3.3"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.3-dev"
+ }
+ },
+ "autoload": {
+ "psr-0": {
+ "Symfony\\Component\\Yaml\\": ""
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "http://symfony.com/contributors"
+ }
+ ],
+ "description": "Symfony Yaml Component",
+ "homepage": "http://symfony.com",
+ "time": "2013-09-22 18:04:39"
+ }
+ ],
+ "packages-dev": [
+
+ ],
+ "aliases": [
+
+ ],
+ "minimum-stability": "stable",
+ "stability-flags": {
+ "mikey179/vfsstream": 20
+ },
+ "platform": [
+
+ ],
+ "platform-dev": [
+
+ ]
+}
View
93 ....YoursSolutions/PHP-frubini/src/TDDMicroExercises/PHP/TelemetrySystem/TelemetryClient.php
@@ -0,0 +1,93 @@
+<?php
+
+namespace TDDMicroExercises\PHP\TelemetrySystem;
+
+class TelemetryClient
+{
+ const DiagnosticMessage = "AT#UD";
+
+ private $_onlineStatus;
+ private $_diagnosticMessageJustSent = false;
+
+ /*private $_connectionEventsSimulator = new Random();
+ private $_randomMessageSimulator = new Random();*/
+
+ public function getOnlineStatus()
+ {
+ return $this->_onlineStatus;
+ }
+
+ public function connect( $telemetryServerConnectionString )
+ {
+ if( is_null($telemetryServerConnectionString) || empty($telemetryServerConnectionString) )
+ {
+ throw new \InvalidArgumentException();
+ }
+
+ // Fake the connection with 20% chances of success
+ //$success = rand(1, 10) <= 2;
+ $success = rand(1, 10) <= 2;
+ $this->_onlineStatus = $success;
+ }
+
+ public function disconnect()
+ {
+ $this->_onlineStatus = false;
+ }
+
+ public function send( $message )
+ {
+ if( is_null($message) || empty($message) ) {
+ throw new \InvalidArgumentException();
+ }
+
+ // The simulation of Send() actually just remember if the last message sent was a diagnostic message.
+ // This information will be used to simulate the Receive(). Indeed there is no real server listening.
+ if ( $message == TelemetryClient::DiagnosticMessage )
+ {
+ $this->_diagnosticMessageJustSent = true;
+
+ }
+ else
+ {
+ $this->_diagnosticMessageJustSent = false;
+ }
+
+ }
+
+ public function receive()
+ {
+ $message = '';
+
+ if($this->_diagnosticMessageJustSent)
+ {
+ // Simulate the reception of the diagnostic message
+ $message = "LAST TX rate................ 100 MBPS\r\n"
+ . "HIGHEST TX rate............. 100 MBPS\r\n"
+ . "LAST RX rate................ 100 MBPS\r\n"
+ . "HIGHEST RX rate............. 100 MBPS\r\n"
+ . "BIT RATE.................... 100000000\r\n"
+ . "WORD LEN.................... 16\r\n"
+ . "WORD/FRAME.................. 511\r\n"
+ . "BITS/FRAME.................. 8192\r\n"
+ . "MODULATION TYPE............. PCM/FM\r\n"
+ . "TX Digital Los.............. 0.75\r\n"
+ . "RX Digital Los.............. 0.10\r\n"
+ . "BEP Test.................... -5\r\n"
+ . "Local Rtrn Count............ 00\r\n"
+ . "Remote Rtrn Count........... 00";
+
+ $this->_diagnosticMessageJustSent = false;
+ }
+ else
+ {
+ $messageLength = rand( 50, 110 );
+ for($i = $messageLength; $i > 0; $i-- )
+ {
+ $message += chr( rand( 40, 126 ) ) ;
+ }
+ }
+
+ return $message;
+ }
+}
View
49 ...ons/PHP-frubini/src/TDDMicroExercises/PHP/TelemetrySystem/TelemetryDiagnosticControls.php
@@ -0,0 +1,49 @@
+<?php
+
+namespace TDDMicroExercises\PHP\TelemetrySystem;
+
+class TelemetryDiagnosticControls
+{
+ const DiagnosticChannelConnectionString = "*111#";
+
+ private $_telemetryClient;
+ private $_diagnosticInfo = '';
+
+ public function __construct()
+ {
+ $this->_telemetryClient = new TelemetryClient();
+ }
+
+ public function getDiagnosticInfo()
+ {
+ return $this->_diagnosticInfo;
+ }
+
+ public function setDiagnosticInfo( $diagnosticInfo )
+ {
+ $this->_diagnosticInfo = $diagnosticInfo;
+ }
+
+ public function checkTransmission()
+ {
+ $this->_diagnosticInfo = '';
+ $this->_telemetryClient->disconnect();
+
+ $retryLeft = 3;
+ while ( $this->_telemetryClient->getOnlineStatus() == false && $retryLeft > 0 )
+ {
+ $this->_telemetryClient->connect(
+ TelemetryDiagnosticControls::DiagnosticChannelConnectionString
+ );
+ $retryLeft -= 1;
+ }
+
+ if($this->_telemetryClient->getOnlineStatus() == false)
+ {
+ throw new \Exception('Unable to connect.');
+ }
+
+ $this->_telemetryClient->send(TelemetryClient::DiagnosticMessage);
+ $this->_diagnosticInfo = $this->_telemetryClient->receive();
+ }
+}
View
37 ...ursSolutions/PHP-frubini/src/TDDMicroExercises/PHP/TirePressureMonitoringSystem/Alarm.php
@@ -0,0 +1,37 @@
+<?php
+
+namespace TDDMicroExercises\PHP\TirePressureMonitoringSystem;
+
+class Alarm
+{
+ const LOW_PRESSURE_TRESHOLD = 17;
+ const HIGH_PRESSURE_TRESHOLD = 21;
+
+ private $sensor;
+ private $alarmOn;
+ private $alarmCount;
+
+ public function __construct(Sensor $sensor) {
+ $this->sensor = $sensor;
+ $this->alarmOn = false;
+ $this->alarmCount = 0;
+ }
+
+
+ public function check()
+ {
+ $psiPressureValue = $this->sensor->popNextPressurePsiValue();
+
+ if ($psiPressureValue < Alarm::LOW_PRESSURE_TRESHOLD
+ || Alarm::HIGH_PRESSURE_TRESHOLD < $psiPressureValue) {
+
+ $this->alarmOn = true;
+ $this->alarmCount += 1;
+ }
+ }
+
+ public function alarmOn()
+ {
+ return $this->alarmOn;
+ }
+}
View
21 ...rsSolutions/PHP-frubini/src/TDDMicroExercises/PHP/TirePressureMonitoringSystem/Sensor.php
@@ -0,0 +1,21 @@
+<?php
+
+namespace TDDMicroExercises\PHP\TirePressureMonitoringSystem;
+
+class Sensor
+{
+ const OFFSET = 16;
+
+ public static function SamplePressure()
+ {
+ // placeholder implementation that simulate a real sensor in a real tire
+ $pressureTelemetryValue = floor(6 * rand() * rand());
+ return $pressureTelemetryValue;
+ }
+
+ public function popNextPressurePsiValue()
+ {
+ $pressureTelemetryValue = self::SamplePressure();
+ return self::OFFSET + $pressureTelemetryValue;
+ }
+}
View
15 ...rsSolutions/PHP-frubini/src/TDDMicroExercises/PHP/TurnTicketDispenser/TicketDispenser.php
@@ -0,0 +1,15 @@
+<?php
+
+namespace TDDMicroExercises\PHP\TurnTicketDispenser;
+
+class TicketDispenser
+{
+
+ public function getTurnTicket()
+ {
+ $newTurnNumber = TurnNumberSequence::getNextTurnNumber();
+ $turnTicket = new TurnTicket($newTurnNumber);
+
+ return $turnTicket;
+ }
+}
View
13 ...olutions/PHP-frubini/src/TDDMicroExercises/PHP/TurnTicketDispenser/TurnNumberSequence.php
@@ -0,0 +1,13 @@
+<?php
+
+namespace TDDMicroExercises\PHP\TurnTicketDispenser;
+
+class TurnNumberSequence
+{
+ private static $_turnNumber = 0;
+
+ public static function getNextTurnNumber()
+ {
+ return self::$_turnNumber++;
+ }
+}
View
18 ...s.YoursSolutions/PHP-frubini/src/TDDMicroExercises/PHP/TurnTicketDispenser/TurnTicket.php
@@ -0,0 +1,18 @@
+<?php
+
+namespace TDDMicroExercises\PHP\TurnTicketDispenser;
+
+class TurnTicket
+{
+ private $_turnNumber;
+
+ public function __construct($turnNumber)
+ {
+ $this->_turnNumber = $turnNumber;
+ }
+
+ public function getTurnNumber()
+ {
+ return $this->_turnNumber;
+ }
+}
View
52 ...c/TDDMicroExercises/PHP/UnicodeFileToHtmlTextConverter/UnicodeFileToHtmlTextConverter.php
@@ -0,0 +1,52 @@
+<?php
+
+namespace TDDMicroExercises\PHP\UnicodeFileToHtmlTextConverter;
+
+class UnicodeFileToHtmlTextConverter
+{
+ private $_filePointer;
+ private $_html;
+ private $_fullFilenameWithPath;
+
+ public function __construct($fullFilenameWithPath)
+ {
+ $this->_fullFilenameWithPath = $fullFilenameWithPath;
+ }
+
+ public function convertToHtml()
+ {
+ if ($this->fileIsReadable()) {
+
+ $this->_html = '';
+
+ $this->_filePointer = $this->openFile();
+
+ while ( $line = fgets($this->_filePointer))
+ {
+ $this->_html .= htmlentities($line);
+ $this->_html .= "<br />";
+ }
+
+ fclose($this->_filePointer);
+
+ return $this->_html;
+ }
+
+ throw new \Exception("Cannot open file");
+ }
+
+ private function openFile()
+ {
+ return fopen($this->_fullFilenameWithPath, 'r+');
+ }
+
+ public function fileIsReadable()
+ {
+ if (false !== $this->openFile()) {
+ return true;
+ }
+ return false;
+ }
+
+}
+
View
97 ...lutions/PHP-frubini/test/TDDMicroExercises/PHP/TirePressureMonitoringSystem/AlarmTest.php
@@ -0,0 +1,97 @@
+<?php
+namespace TDDMicroExercises\PHP\TirePressureMonitoringSystem;
+/**
+ * Class AlarmTest
+ * @package TDDMicroExercises\PHP\TirePressureMonitoringSystem
+ */
+class AlarmTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * @var Alarm
+ */
+ protected $alarm;
+
+ /**
+ * @var \PHPUnit_Framework_MockObject_MockObject
+ */
+ protected $sensor;
+
+ public function setUp()
+ {
+ $this->sensor = $this->getMock(
+ 'TDDMicroExercises\PHP\TirePressureMonitoringSystem\Sensor',
+ array('popNextPressurePsiValue')
+ );
+
+ $this->alarm = new Alarm($this->sensor);
+
+ }
+
+ /**
+ * test the alarm is not triggered between the threshold boundaries
+ */
+ public function testTheAlarmIsNotTriggeredForMinAndMaxPressureTreshold()
+ {
+ $this->assertFalse($this->alarm->alarmOn());
+
+ $this->sensor->expects($this->any())
+ ->method('popNextPressurePsiValue')
+ ->will($this->returnValue(Alarm::LOW_PRESSURE_TRESHOLD));
+
+ $this->alarm->check();
+ $this->assertFalse($this->alarm->alarmOn());
+
+ $this->sensor->expects($this->any())
+ ->method('popNextPressurePsiValue')
+ ->will($this->returnValue(Alarm::HIGH_PRESSURE_TRESHOLD));
+
+ $this->alarm->check();
+ $this->assertFalse($this->alarm->alarmOn());
+ }
+
+ /**
+ * Test the alarm is triggered when the pressure is lower or higher of the threshold values
+ */
+ public function testTheAlarmTriggeredForPressuresOutsideTheTrashold()
+ {
+ $this->assertFalse($this->alarm->alarmOn());
+
+ $this->sensor->expects($this->any())
+ ->method('popNextPressurePsiValue')
+ ->will($this->returnValue(Alarm::LOW_PRESSURE_TRESHOLD - 1));
+
+ $this->alarm->check();
+ $this->assertTrue($this->alarm->alarmOn());
+
+ $this->sensor->expects($this->any())
+ ->method('popNextPressurePsiValue')
+ ->will($this->returnValue(Alarm::HIGH_PRESSURE_TRESHOLD + 1));
+
+ $this->alarm->check();
+ $this->assertTrue($this->alarm->alarmOn());
+ }
+
+
+ /**
+ * Test that the alarm is triggered when the pressure return to normal
+ * if it was previously outside the threshold boundaries.
+ */
+ public function testNormalPressureValueAfterAnAlarmShouldKeepAlarmOn()
+ {
+ $this->assertFalse($this->alarm->alarmOn());
+
+ $this->sensor->expects($this->any())
+ ->method('popNextPressurePsiValue')
+ ->will($this->returnValue(Alarm::LOW_PRESSURE_TRESHOLD - 1));
+
+ $this->alarm->check();
+ $this->assertTrue($this->alarm->alarmOn());
+
+ $this->sensor->expects($this->any())
+ ->method('popNextPressurePsiValue')
+ ->will($this->returnValue(Alarm::HIGH_PRESSURE_TRESHOLD));
+
+ $this->alarm->check();
+ $this->assertTrue($this->alarm->alarmOn());
+ }
+}
View
70 ...DMicroExercises/PHP/UnicodeFileToHtmlTextConverter/UnicodeFileToHtmlTextConverterTest.php
@@ -0,0 +1,70 @@
+<?php
+/**
+ * Date: 6/10/13
+ * Time: 11:25 AM
+ * @author Federico Rubini
+ */
+
+namespace TDDMicroExercises\PHP\UnicodeFileToHtmlTextConverter;
+
+use org\bovigo\vfs\vfsStream;
+use org\bovigo\vfs\vfsStreamFile;
+
+class UnicodeFileToHtmlTextConverterTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * @var UnicodeFileToHtmlTextConverter
+ */
+ protected $converter;
+
+ /**
+ * Virtual file system
+ *
+ * @var vfsStreamFile
+ */
+ protected $fileStream;
+
+ /**
+ * @var \org\bovigo\vfs\vfsStreamDirectory
+ */
+ protected $root;
+
+ public function setUp()
+ {
+ // Create the file in the virtual file system
+ $this->root = vfsStream::setup('home');
+ $this->fileStream = vfsStream::url('home/test.txt');
+ file_put_contents($this->fileStream, "The new contents of the file\nthis is the second line");
+
+ // Pass filename to the Converter
+ $this->converter = new UnicodeFileToHtmlTextConverter(vfsStream::url('home/test.txt'));
+
+ }
+
+
+ public function testFileCanBeRead()
+ {
+ $this->assertFalse(file_get_contents(vfsStream::url('home/test.txt')) === false);
+ $this->assertTrue($this->converter->fileIsReadable());
+ }
+
+ /**
+ * Test the conversion to html
+ */
+ public function testConversionToHtml()
+ {
+ $this->assertStringEndsWith('line', file_get_contents(vfsStream::url('home/test.txt')));
+ $this->assertStringEndsWith('<br />', $this->converter->convertToHtml());
+ }
+
+ public function testAllLinesEndWithBrake()
+ {
+ $this->assertEquals(2, substr_count( $this->converter->convertToHtml(), '<br />'));
+ }
+
+ public function testConvertHtmlEntities()
+ {
+ file_put_contents($this->fileStream, "Apples&Pears&Oranjes");
+ $this->assertEquals("Apples&amp;Pears&amp;Oranjes<br />", $this->converter->convertToHtml());
+ }
+}
View
8 TDDMicroExercises.YoursSolutions/PHP-frubini/test/bootstrap.php
@@ -0,0 +1,8 @@
+<?php
+/**
+ * Date: 6/6/13
+ * Time: 3:54 PM
+ * @author Federico Rubini <f.rubini@keesing.com>
+ */
+
+require __DIR__ . '/../vendor/autoload.php';
View
2 TDDMicroExercises.YoursSolutions/PHP-frubini/test/phpunit.xml
@@ -0,0 +1,2 @@
+<phpunit bootstrap="bootstrap.php">
+</phpunit>

No commit comments for this range

Something went wrong with that request. Please try again.