Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions app/libraries/Calculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,29 @@ public function add($x, $y)
}
return $x + $y;
}

public function sub($x, $y)
{
if ( !is_numeric($x) || !is_numeric($y)) {
throw new \InvalidArgumentException;
}
return $x - $y;
}

public function mul($x, $y)
{
if ( !is_numeric($x) || !is_numeric($y)) {
throw new \InvalidArgumentException;
}
return $x * $y;
}

public function div($x, $y)
{
if ( !is_numeric($x) || !is_numeric($y)) {
throw new \InvalidArgumentException;
}
return $x / $y;
}

}
55 changes: 53 additions & 2 deletions test/CalculatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,40 @@ public function setUp()
$this->calculator = new Calculator;
}

public function inputNumbers()
public function inputNumbersForSum()
{
return [
[2, 2, 4],
[2.5, 2.5, 5]
];
}

public function inputNumbersForSubstract()
{
return [
[2, 2, 0],
[-20, -5, -15]
];
}

public function inputNumbersForMultiply()
{
return [
[2, 4, 8],
[10, 20, 200]
];
}

public function inputNumbersForDivide()
{
return [
[12, 6, 2],
[10, 5, 2]
];
}

/**
* @dataProvider inputNumbers
* @dataProvider inputNumbersForSum
*/
public function testCanAddNumbers($x, $y, $sum)
{
Expand All @@ -32,5 +56,32 @@ public function testThrowsExceptionIfNonNumberIsPassed()
{
$calc = new Calculator;
$calc->add('a', 'b');
$calc->sub('2', 'b');
$calc->mul('3', 'c');
$calc->div('20', 'a');
}

/**
* @dataProvider inputNumbersForSubstract
*/
public function testCanSubstractNumber($x, $y, $sub)
{
$this->assertEquals($sub, $this->calculator->sub($x, $y));
}

/**
* @dataProvider inputNumbersForMultiply
*/
public function testCanMultiplyNumbers($x, $y, $mul)
{
$this->assertEquals($mul, $this->calculator->mul($x, $y));
}

/**
* @dataProvider inputNumbersForDivide
*/
public function testCanDivideNumbers($x, $y, $div)
{
$this->assertEquals($div, $this->calculator->div($x, $y));
}
}
4 changes: 2 additions & 2 deletions vendor/autoload.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

// autoload.php generated by Composer
// autoload.php @generated by Composer

require_once __DIR__ . '/composer' . '/autoload_real.php';

return ComposerAutoloaderInit4cfd9c3a1c44ce88293b671eed43b735::getLoader();
return ComposerAutoloaderInit2ad21367cd9ccec772a6c779bfd35271::getLoader();
81 changes: 60 additions & 21 deletions vendor/composer/ClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ClassLoader

public function getPrefixes()
{
return $this->prefixes;
return call_user_func_array('array_merge', $this->prefixes);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im not sure why this line gets changed, could anybody tell me why ?

}

public function getFallbackDirs()
Expand All @@ -75,28 +75,63 @@ public function addClassMap(array $classMap)
}

/**
* Registers a set of classes
* Registers a set of classes, merging with any others previously set.
*
* @param string $prefix The classes prefix
* @param array|string $paths The location(s) of the classes
* @param string $prefix The classes prefix
* @param array|string $paths The location(s) of the classes
* @param bool $prepend Prepend the location(s)
*/
public function add($prefix, $paths)
public function add($prefix, $paths, $prepend = false)
{
if (!$prefix) {
foreach ((array) $paths as $path) {
$this->fallbackDirs[] = $path;
if ($prepend) {
$this->fallbackDirs = array_merge(
(array) $paths,
$this->fallbackDirs
);
} else {
$this->fallbackDirs = array_merge(
$this->fallbackDirs,
(array) $paths
);
}

return;
}
if (isset($this->prefixes[$prefix])) {
$this->prefixes[$prefix] = array_merge(
$this->prefixes[$prefix],
(array) $paths

$first = $prefix[0];
if (!isset($this->prefixes[$first][$prefix])) {
$this->prefixes[$first][$prefix] = (array) $paths;

return;
}
if ($prepend) {
$this->prefixes[$first][$prefix] = array_merge(
(array) $paths,
$this->prefixes[$first][$prefix]
);
} else {
$this->prefixes[$prefix] = (array) $paths;
$this->prefixes[$first][$prefix] = array_merge(
$this->prefixes[$first][$prefix],
(array) $paths
);
}
}

/**
* Registers a set of classes, replacing any others previously set.
*
* @param string $prefix The classes prefix
* @param array|string $paths The location(s) of the classes
*/
public function set($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirs = (array) $paths;

return;
}
$this->prefixes[substr($prefix, 0, 1)][$prefix] = (array) $paths;
}

/**
Expand Down Expand Up @@ -142,7 +177,7 @@ public function unregister()
* Loads the given class or interface.
*
* @param string $class The name of the class
* @return bool|null True, if loaded
* @return bool|null True if loaded, null otherwise
*/
public function loadClass($class)
{
Expand All @@ -158,10 +193,11 @@ public function loadClass($class)
*
* @param string $class The name of the class
*
* @return string|null The path, if found
* @return string|false The path if found, false otherwise
*/
public function findFile($class)
{
// work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731
if ('\\' == $class[0]) {
$class = substr($class, 1);
}
Expand All @@ -172,21 +208,24 @@ public function findFile($class)

if (false !== $pos = strrpos($class, '\\')) {
// namespaced class name
$classPath = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, 0, $pos)) . DIRECTORY_SEPARATOR;
$classPath = strtr(substr($class, 0, $pos), '\\', DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
$className = substr($class, $pos + 1);
} else {
// PEAR-like class name
$classPath = null;
$className = $class;
}

$classPath .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
$classPath .= strtr($className, '_', DIRECTORY_SEPARATOR) . '.php';

foreach ($this->prefixes as $prefix => $dirs) {
if (0 === strpos($class, $prefix)) {
foreach ($dirs as $dir) {
if (file_exists($dir . DIRECTORY_SEPARATOR . $classPath)) {
return $dir . DIRECTORY_SEPARATOR . $classPath;
$first = $class[0];
if (isset($this->prefixes[$first])) {
foreach ($this->prefixes[$first] as $prefix => $dirs) {
if (0 === strpos($class, $prefix)) {
foreach ($dirs as $dir) {
if (file_exists($dir . DIRECTORY_SEPARATOR . $classPath)) {
return $dir . DIRECTORY_SEPARATOR . $classPath;
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions vendor/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

// autoload_classmap.php generated by Composer
// autoload_classmap.php @generated by Composer

$vendorDir = dirname(__DIR__);
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
Expand Down
4 changes: 2 additions & 2 deletions vendor/composer/autoload_namespaces.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

// autoload_namespaces.php generated by Composer
// autoload_namespaces.php @generated by Composer

$vendorDir = dirname(__DIR__);
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
Expand Down
18 changes: 9 additions & 9 deletions vendor/composer/autoload_real.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

// autoload_real.php generated by Composer
// autoload_real.php @generated by Composer

class ComposerAutoloaderInit4cfd9c3a1c44ce88293b671eed43b735
class ComposerAutoloaderInit2ad21367cd9ccec772a6c779bfd35271
{
private static $loader;

Expand All @@ -15,28 +15,28 @@ public static function loadClassLoader($class)

public static function getLoader()
{
if (null !== static::$loader) {
return static::$loader;
if (null !== self::$loader) {
return self::$loader;
}

spl_autoload_register(array('ComposerAutoloaderInit4cfd9c3a1c44ce88293b671eed43b735', 'loadClassLoader'));
static::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInit4cfd9c3a1c44ce88293b671eed43b735', 'loadClassLoader'));
spl_autoload_register(array('ComposerAutoloaderInit2ad21367cd9ccec772a6c779bfd35271', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInit2ad21367cd9ccec772a6c779bfd35271', 'loadClassLoader'));

$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);

$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
$loader->add($namespace, $path);
$loader->set($namespace, $path);
}

$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
$loader->addClassMap($classMap);
}

$loader->register();
$loader->register(true);

return $loader;
}
Expand Down