Skip to content
This repository has been archived by the owner on Jul 31, 2022. It is now read-only.

Commit

Permalink
Merge pull request #30 from tbreuss/develop
Browse files Browse the repository at this point in the history
Several updates
  • Loading branch information
tbreuss committed Oct 20, 2018
2 parents 3866886 + 6ea2f4b commit 17fdf26
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# PVC – A Minimal P[HP] [M]VC Framework

[![Travis](https://img.shields.io/travis/tbreuss/pvc.svg)](https://travis-ci.org/tbreuss/pvc)
[![Scrutinizer](https://img.shields.io/scrutinizer/g/tbreuss/pvc.svg)](https://scrutinizer-ci.com/g/tbreuss/pvc/)
[![Packagist](https://img.shields.io/packagist/dt/tebe/pvc.svg)](https://packagist.org/packages/tebe/pvc)
[![GitHub (pre-)release](https://img.shields.io/github/release/tbreuss/pvc/all.svg)](https://github.com/tbreuss/pvc/releases)
[![License](https://img.shields.io/github/license/tbreuss/pvc.svg)](https://github.com/tbreuss/pvc/blob/master/LICENSE)
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"phpcbf": "./vendor/bin/phpcbf",
"phpcs": "./vendor/bin/phpcs",
"phpmd": "./vendor/bin/phpmd ./src text codesize,design,naming,unusedcode",
"phpunit": "./vendor/bin/phpunit"
"phpunit": "./vendor/bin/phpunit",
"run": "php -S localhost:9999 -t ./example/public >/dev/null 2>&1"
}
}
15 changes: 10 additions & 5 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Application
private function __construct()
{
$this->setEventDispatcher(new EventDispatcher());
$this->middlewares = [];
$this->setMiddlewares([]);
}

/**
Expand All @@ -75,7 +75,7 @@ public static function instance(): Application

/**
* @param array $config
* @return $this
* @return Application
*/
public function setConfig(array $config)
{
Expand All @@ -93,7 +93,7 @@ public function getConfig(): Config

/**
* @param ServerRequestInterface $request
* @return $this
* @return Application
*/
public function setRequest(ServerRequestInterface $request)
{
Expand All @@ -111,10 +111,12 @@ public function getRequest(): ServerRequestInterface

/**
* @param View $view
* @return Application
*/
public function setView(View $view)
{
$this->view = $view;
return $this;
}

/**
Expand All @@ -128,6 +130,7 @@ public function getView(): View
$helpers = new ViewHelpers();
$view = new View($viewsPath, $helpers);

// TODO move to own ViewExtension class
$view->registerHelper('escape', function (string $string) {
return htmlspecialchars($string);
});
Expand Down Expand Up @@ -156,7 +159,7 @@ public function addMiddleware(MiddlewareInterface $middleware): Application

/**
* @param MiddlewareInterface[] $middlewares
* @return $this
* @return Application
*/
public function setMiddlewares(array $middlewares): Application
{
Expand All @@ -168,10 +171,12 @@ public function setMiddlewares(array $middlewares): Application

/**
* @param EventDispatcher $eventDispatcher
* @return Application
*/
private function setEventDispatcher(EventDispatcher $eventDispatcher)
public function setEventDispatcher(EventDispatcher $eventDispatcher)
{
$this->eventDispatcher = $eventDispatcher;
return $this;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Controller/ErrorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ class ErrorController extends BaseController

/**
* @param Throwable $error
* @return ErrorController
*/
public function setError(Throwable $error)
{
$this->error = $error;
return $this;
}

/**
Expand Down
95 changes: 95 additions & 0 deletions tests/ApplicationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

namespace Tebe\Pvc\Tests;

use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Tebe\HttpFactory\HttpFactory;
use Tebe\Pvc\Application;
use Tebe\Pvc\Config;
use Tebe\Pvc\Event\EventDispatcher;
use Tebe\Pvc\Event\EventHandler;
use Tebe\Pvc\View\View;
use Tebe\Pvc\View\ViewHelpers;

class ApplicationTest extends TestCase
{
/** @var Application */
private $app;

public function setUp()
{
$this->app = Application::instance();
}

public function testSetConfig()
{
$this->assertInstanceOf(Application::class, $this->app->setConfig([]));
}

public function testGetConfig()
{
$this->assertInstanceOf(Config::class, $this->app->getConfig());
}

public function testSetRequest()
{
$request = (new HttpFactory())->createServerRequest('get', '/');
$this->assertInstanceOf(Application::class, $this->app->setRequest($request));
}

public function testGetRequest()
{
$this->assertInstanceOf(ServerRequestInterface::class, $this->app->getRequest());
}

public function testSetView()
{
$view = new View(__DIR__ . '/resources/views', new ViewHelpers());
$this->assertInstanceOf(Application::class, $this->app->setView($view));
}

public function testGetView()
{
$this->assertInstanceOf(View::class, $this->app->getView());
}

public function testAddMiddleware()
{
$middleware = $this->getMockBuilder(MiddlewareInterface::class)->getMock();
$this->assertInstanceOf(Application::class, $this->app->addMiddleware($middleware));
}

public function testSetMiddlewares()
{
$middlewares = [$this->getMockBuilder(MiddlewareInterface::class)->getMock()];
$this->assertInstanceOf(Application::class, $this->app->setMiddlewares($middlewares));
}

public function testSetEventDispatcher()
{
$this->assertInstanceOf(Application::class, $this->app->setEventDispatcher(new EventDispatcher()));
}

public function testGetEventDispatcher()
{
$this->assertInstanceOf(EventDispatcher::class, $this->app->getEventDispatcher());
}

public function testAddEventHandler()
{
$eventHandler = $this->getMockBuilder(EventHandler::class)->getMock();
$this->assertInstanceOf(Application::class, $this->app->addEventHandler('name', $eventHandler));
}

// TODO implement test
public function testRun()
{
}

public function testSetViewExtensions()
{
$this->assertINstanceOf(Application::class, $this->app->setViewExtensions([]));
}
}

0 comments on commit 17fdf26

Please sign in to comment.