Skip to content

Commit

Permalink
Reordered docs with new features
Browse files Browse the repository at this point in the history
  • Loading branch information
wdalmut committed Dec 31, 2013
1 parent cc5058e commit 87ad7e7
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 13 deletions.
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,15 @@ $loader = include __DIR__ . '/vendor/autoload.php';
$loader->add("Your", __DIR__ . '/../src');
$conf = include __DIR__ . '/../configs/app.php';
$app = new \UpCloo\App([$conf]);
$config = new UpCloo\App\Config\ArrayProcessor();
$config->appendConfig(include __DIR__ . '/../configs/app.php');
$engine = new UpCloo\App\Engine();
$boot = new UpCloo\App\Boot($config);
$app = new UpCloo\App($engine, $boot);
$app->run();
```

Here is a config (configs/app.php)
Expand Down Expand Up @@ -68,7 +74,7 @@ return array(
),
"factories" => array(
"example" => function(\Zend\ServiceManager\ServiceLocatorInterface $sl) {
return "that-service";
return "hello";
}
),
)
Expand All @@ -81,11 +87,16 @@ Start with a controller (src/Your/Controller/Name.php)
<?php
namespace Your\Controller;
use UpCloo\Controller\ServiceManager;
class Name
{
use ServiceManager;
public function hello()
{
return "world";
$hello = $this->services()->get("example");
return $hello . " " . "world";
}
}
```
Expand Down
14 changes: 9 additions & 5 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,22 @@ Any `callable` hook is valid ::
Overload your configuration
---------------------------

You can pass to your `App` different configurations. The framework merge those
You can pass to your `Boot` different configurations. The framework merge those
together in order to obtain a single configuration.

This thing could be useful in order to obtain the right configuration for the
current environment.

For example see something like this: ::

$app = new \UpCloo\App([
include __DIR__ . '/../config/app.php',
include __DIR__ . "/../config/app.{$env}.php",
]);
$config = new \UpCloo\App\Config\ArrayProcessor();

$config->appendConfig(include __DIR__ . "/../configs/app.php");
$config->appendConfig(include __DIR__ . "/../configs/app.{$env}.php");

$boot = new \UpCloo\App\Boot($config);

...

In this way the conf loaded from `app.php` is overwritten by the second configuration
and so on. You can load how many conf you need.
Expand Down
90 changes: 89 additions & 1 deletion docs/controllers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,38 @@ the first argument is the redirect location.
The Redirector traits uses the "Response trait" by itself, for that reason when you use
the redirector the Response traits is automatically added to your controller.

ServiceManager
--------------

You can request anything from the service locator through just using the
`ServiceManager` trait. ::

<?php
namespace Your\NM;

use UpCloo\Controller\ServiceManager;

class TheHookContainer
{
use ServiceManager;

public function anHook()
{
$aService = $this->services()->get("a-service");

...
}
}


EventManager
------------

Inside an event you can attach and fire other events adding the EventManager
trait::

<?php
namespace Your\\NM;
namespace Your\NM;

use UpCloo\Controller\EventManager;

Expand All @@ -139,10 +163,74 @@ trait::

public function anHook()
{
// Attach something to an event
$this->events()->attach("finish", function() {
//Good bye cruel world!
});

// Trigger a custom event...
$this->events()->trigger("my.hook.event", $this, ["name" => "a name"]);
}
}

Test your controllers
---------------------

You can test your controller in isolation from the entire application, you have
just to prepare things that you need and inject into your controller.

See an example: ::

<?php
namespace Your\NM;

use UpCloo\Controller\EventManager;

class Controller
{
use EventManager;

public function myHook($event)
{
$this->events()->trigger("my.hook.start", $this);

... // do something...

$this->events()->trigger("my.hook.finish", $this, $data);
return $data;
}
}

Your tests could be something like this: ::

<?php
namespace UpCloo\NM;

use Zend\EventManager\EventManager;
use UpCloo\Test\ControllerTestUtils;

class ControllerTest extends \PHPUnit_Framework_TestCase
{
use ControllerTestUtils;

private $object;

public function setUp()
{
// Prepare the controller
$this->object = new Controller();
$this->object->setEventManager(new EventManager());
}

public function testWorkingAction()
{
$event = $this->getEventFromParams([
"param" => "hello"
]);

$data = $this->object->myHook($event);

// asserts on data
}
}

60 changes: 58 additions & 2 deletions docs/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Getting Started with UpCloo Framework

The base folder structure is: whatever you want...

I suggest something like this: ::
We suggest something like this: ::

- configs
- src
Expand Down Expand Up @@ -34,7 +34,14 @@ the `index.php` file. ::
$loader->add("My", __DIR__ . '/../src');

$conf = include __DIR__ . "/../configs/app.php";
$app = new \UpCloo\App([$conf]);

$config = new UpCloo\App\Config\ArrayProcessor();
$config->appendConfig($conf);

$boot = new UpCloo\App\Boot($config);
$engine = new UpCloo\App\Engine();

$app = new UpCloo\App($engine, $boot);
$app->run();

As you can see the first to line uses the composer autoloader in order to
Expand Down Expand Up @@ -155,3 +162,52 @@ The output should be something similar to this: ::

Now you can continue with more interesting things!

Integration testing
-------------------

You can test your controller in isolation (see :doc:`controllers`) or you can
run the whole application. If you are interested in this last thing, you have
to inherits from `UpCloo\Test\WebTestCase` during testing. ::

<?php
namespace Your\NM;

use UpCloo\Test\WebTestCase;

class MyControllerTest extends WebTestCase
{
public function setUp()
{
$this->appendConfig([
"router" => [
... // Routes
],
"services" => [
... // A conf
],
...
]);
}

public function testMyAction()
{
$response = $this->dispatch("/my-action"); //get method

$this->assertEquals(200, $response->getStatusCode());
//... more assert

$content = $response->getContent();
//...
}
}

The `dispatch` method signature is: ::

public function dispatch($url, $method = "GET", array $params = array())

Possibile methods are:

* GET
* POST
* PUT

2 changes: 1 addition & 1 deletion src/UpCloo/App/Boot.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
namespace UpCloo\App;

use Zend\ServiceManager\ServiceManager;
use Zend\EventManager\EventManager;
use Zend\ServiceManager\ServiceManager;
use Zend\ServiceManager\Config as ServiceManagerConfig;

class Boot
Expand Down

0 comments on commit 87ad7e7

Please sign in to comment.