Skip to content

Commit

Permalink
add simple tests
Browse files Browse the repository at this point in the history
  • Loading branch information
moolex committed Jul 29, 2019
1 parent fc8fa2c commit e131e82
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 4 deletions.
26 changes: 26 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
language: php

php:
- '7.1'
- '7.2'
- '7.3'

dist: trusty
sudo: false

cache:
directories:
- ~/.composer
- ~/.php-ext

before_install:
- source <(curl -sL https://github.com/carno-php/travis-ci/raw/master/tests-prepare.sh)

install:
- composer update

script:
- testing

after_success:
- coveralls
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
},
"files": ["utils.php"]
},
"autoload-dev": {
"psr-4": {
"Carno\\Log\\Tests\\": "tests"
}
},
"minimum-stability": "dev",
"extra": {
"branch-alias": {
Expand Down
22 changes: 22 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
>
<testsuites>
<testsuite name="Default">
<directory>tests</directory>
</testsuite>
</testsuites>

<logging>
<log type="coverage-clover" target="coverage.xml"/>
</logging>

<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>
</phpunit>
2 changes: 1 addition & 1 deletion src/Outputter/Stdout.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ class Stdout implements Outputter
*/
public function write(string $data) : void
{
echo $data;
PHP_SAPI === 'cli' && print $data;
}
}
4 changes: 2 additions & 2 deletions src/Outputter/TCP.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ public function __construct(Address $endpoint)
{
if (!class_exists(Socket::class)) {
trigger_error('NWSocket not loaded, tcp outputter will not working', E_USER_WARNING);
throw new MissingNWSocketException;
throw new MissingNWSocketException();
}

$this->endpoint = $endpoint;

$this->events = (new Events)
$this->events = (new Events())
->attach(Events\Socket::CONNECTED, function () {
$this->connected();
})
Expand Down
2 changes: 1 addition & 1 deletion src/Replicator/LogIO.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function send(string $scene, string $level, string $message, array $conte
{
$buf = '';

$node = $this->env->app().(($t = $this->env->tagged()) ? sprintf(':%s', $t) : '');
$node = $this->env->app() . (($t = $this->env->tagged()) ? sprintf(':%s', $t) : '');
$stream = $scene;

if (!isset($this->assets[$node][$stream])) {
Expand Down
30 changes: 30 additions & 0 deletions tests/LoggerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Logger Test
* User: moyo
* Date: Jul 29, 2019
* Time: 10:39
*/

namespace Carno\Log\Tests;

use Carno\Log\Logger;
use PHPUnit\Framework\TestCase;
use function Carno\Config\conf;

class LoggerTest extends TestCase
{
public function testFunc()
{
conf()->set('log.addr', '???');
logger('test')->info('test1');

conf()->set('test.log.format', 'json');
logger('test')->info('test2');

conf()->set('log.level', 'debug');
logger()->debug('test3');

$this->assertTrue(logger() instanceof Logger);
}
}

0 comments on commit e131e82

Please sign in to comment.