PHP Classes
elePHPant
Icontem

File: test/Services/Http/HttpServiceTest.php

Recommend this page to a friend!
  Classes of Artur Graniszewski  >  ZEUS for PHP  >  test/Services/Http/HttpServiceTest.php  >  Download  
File: test/Services/Http/HttpServiceTest.php
Role: Unit test script
Content type: text/plain
Description: Unit test script
Class: ZEUS for PHP
Manage the execution of multiple parallel tasks
Author: By
Last change: Memcached server switched to ZEUS socket server + test fixes
Date: 1 month ago
Size: 2,288 bytes
 

Contents

Class file image Download
<?php

namespace ZeusTest\Services\Http;

use
PHPUnit_Framework_TestCase;
use
Zend\Http\Request;
use
Zend\Http\Response;
use
Zend\Log\Logger;
use
Zend\Log\Writer\Mock;
use
Zeus\ServerService\Http\Service;
use
ZeusTest\Helpers\ZeusFactories;

class
HttpServiceTest extends PHPUnit_Framework_TestCase
{
    use
ZeusFactories;

   
/**
     * @return Service
     */
   
protected function getService()
    {
       
$sm = $this->getServiceManager();
       
$scheduler = $this->getScheduler();
       
$logger = $scheduler->getLogger();

       
$service = $sm->build(Service::class,
            [
               
'scheduler_adapter' => $scheduler,
               
'logger_adapter' => $logger,
               
'config' =>
                [
                   
'service_settings' => [
                   
'listen_port' => 7070,
                   
'listen_address' => '0.0.0.0',
                   
'keep_alive_enabled' => true,
                   
'keep_alive_timeout' => 5,
                   
'max_keep_alive_requests_limit' => 100,
                   
'blocked_file_types' => [
                       
'php',
                       
'phtml'
                   
]
                ]
            ]
        ]);

        return
$service;
    }

    public function
testServiceCreation()
    {
       
$service = $this->getService();
       
$service->start();
       
$service->stop();
    }

    public function
testLogger()
    {
       
$request = Request::fromString("GET /test?foo=bar HTTP/1.1\r\nHost: localhost\r\nUser-Agent: PHPUNIT\r\nReferer: http://foo.bar\r\n\r\n");
       
$response = new Response();
       
$response->setVersion('1.1');
       
$response->setMetadata('dataSentInBytes', 1234);
       
$response->setStatusCode(201);
       
$request->setMetadata('remoteAddress', '192.168.1.2');

       
$service = $this->getService();

       
$mockWriter = new Mock();
       
$nullLogger = new Logger();
       
$nullLogger->addWriter($mockWriter);
       
$service->setLogger($nullLogger);

       
$service->logRequest($request, $response);
       
$this->assertEquals('192.168.1.2 - - "GET /test?foo=bar HTTP/1.1" 201 1234 "http://foo.bar" "PHPUNIT"', $mockWriter->events[0]['message']);
    }
}