Skip to content

Commit

Permalink
Add first tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Falaleev Maxim committed Oct 17, 2014
1 parent 3177196 commit 84ae1d3
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 13 deletions.
12 changes: 12 additions & 0 deletions Tests/Application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Mindy\Application\Tests;

use Mindy\Application\BaseApplication;

class Application extends BaseApplication
{
public function processRequest()
{
}
}
36 changes: 36 additions & 0 deletions Tests/Cases/Application/ApplicationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Mindy\Application\Tests;

class ApplicationTest extends TestCase
{
public function testSimple()
{
$config = [
'basePath' => __DIR__ . '/../../app',
'params' => [
'foo' => 'bar'
],
];
$app = new Application($config);

// Unique id test
$this->assertNotNull($app->getId());

// Base paths test
$this->assertEquals(realpath(__DIR__ . '/../../app'), $app->getBasePath());
$this->assertEquals(realpath(__DIR__ . '/../../app/Modules'), $app->getModulePath());
$this->assertEquals(realpath(__DIR__ . '/../../app/runtime'), $app->getRuntimePath());

// Params test
$this->assertEquals(['foo' => 'bar'], $app->getParams()->all());

// Timezones test
$this->assertEquals(date_default_timezone_get(), $app->getTimeZone());
$app->setTimeZone('UTC');
$this->assertEquals('UTC', $app->getTimeZone());

// Test Translate component
$this->assertInstanceOf('\Mindy\Locale\Translate', $app->getTranslate());
}
}
11 changes: 11 additions & 0 deletions Tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Mindy\Application\Tests;

use PHPUnit_Framework_TestCase;

class TestCase extends PHPUnit_Framework_TestCase
{

}

Empty file added Tests/app/.gitkeep
Empty file.
Empty file added Tests/app/Modules/.gitkeep
Empty file.
Empty file added Tests/app/runtime/.gitkeep
Empty file.
5 changes: 5 additions & 0 deletions Tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/TestCase.php';
require_once __DIR__ . '/Application.php';
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
"mindy/http": "dev-master",
"mindy/middleware": "dev-master",
"mindy/logger": "dev-master",
"mindy/router": "dev-master"
"mindy/router": "dev-master",
"mindy/event": "dev-master",
"mindy/security": "dev-master",
"mindy/session": "dev-master"
},
"require-dev": {
"satooshi/php-coveralls": "dev-master"
Expand Down
43 changes: 43 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="true"
syntaxCheck="true"
bootstrap="Tests/bootstrap.php"
>

<php>
<ini name="memory_limit" value="-1"/>
<ini name="display_errors" value="1"/>
<ini name="error_reporting" value="-1"/>
</php>

<testsuites>
<testsuite name="Application">
<directory>./Tests/Cases/Application/</directory>
</testsuite>
</testsuites>

<groups>
<exclude>
<group>benchmark</group>
</exclude>
</groups>

<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>

<logging>
<!--<log type="coverage-html" target="build/logs/coverage" charset="UTF-8"-->
<!--yui="true" highlight="true" lowUpperBound="50" highLowerBound="80"/>-->
</logging>
</phpunit>
12 changes: 0 additions & 12 deletions src/Mindy/Application/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,6 @@ public function parseRoute()
return $this->getUrlManager()->parseUrl($this->getRequest());
}

public function setComponents($components, $merge = true)
{
foreach ($components as $name => $component) {
$this->locator->set($name, $component);
}
}

/**
* @throws \Mindy\Exception\Exception
* @return \Modules\User\Models\User instance the user session information
Expand All @@ -105,11 +98,6 @@ public function getUser()
return $auth->getModel();
}

public function getComponent($id, $createIfNull = true)
{
return $this->locator->get($id, false);
}

/**
* Creates the controller and performs the specified action.
* @param string $route the route of the current request. See {@link createController} for more details.
Expand Down
7 changes: 7 additions & 0 deletions src/Mindy/Application/BaseApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -1067,4 +1067,11 @@ protected function registerCoreComponents()
$this->locator = new ServiceLocator();
$this->setComponents($components);
}

public function setComponents($components, $merge = true)
{
foreach ($components as $name => $component) {
$this->locator->set($name, $component);
}
}
}

0 comments on commit 84ae1d3

Please sign in to comment.