Skip to content

Commit

Permalink
统计服务增加测试 #2028
Browse files Browse the repository at this point in the history
  • Loading branch information
twinh committed Nov 13, 2016
1 parent bb2d9c5 commit c50678c
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 2 deletions.
31 changes: 31 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
language: php

php:
- '5.4'
- '5.5'
- '5.6'
- '7.0'
- hhvm
- nightly

matrix:
fast_finish: true
allow_failures:
- php: hhvm
- php: nightly

before_install:
- phpenv config-add tests/travis.ini

install:
- composer require satooshi/php-coveralls --no-interaction

before_script:
- mysql -e 'CREATE DATABASE IF NOT EXISTS test;'
- mysql -e 'CREATE DATABASE IF NOT EXISTS app;'

script:
- phpunit --verbose --stderr --coverage-clover build/logs/clover.xml

after_success:
- travis_retry php vendor/bin/coveralls -v
11 changes: 9 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@
],
"license": "MIT",
"require": {
"miaoxing/plugin": "*"
"miaoxing/plugin": "@dev"
},
"autoload": {
"psr-4": {
"Miaoxing\\Stat\\": "src"
}
}
},
"autoload-dev": {
"psr-4": {
"MiaoxingTest\\Stat\\": "tests"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
25 changes: 25 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>

<phpunit backupGlobals="false"
colors="true"
bootstrap="vendor/miaoxing/plugin/tests/bootstrap.php"
>

<testsuites>
<testsuite name="Default Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>.</directory>
<exclude>
<directory>./data</directory>
<directory>./docs</directory>
<directory>./tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
33 changes: 33 additions & 0 deletions tests/Service/StatTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace MiaoxingTest\Stat\Stests\Service;

use Miaoxing\Plugin\Test\BaseTestCase;

/**
* 统计服务
*/
class StatTest extends BaseTestCase
{
/**
* 记录一条日志
*/
public function testLog()
{
$db = $this->getServiceMock('db', ['insert']);
wei()->stat->db = $db;

$db->expects($this->once())
->method('insert')
->with('test', $this->logicalAnd(
$this->arrayHasKey('a'),
$this->arrayHasKey('appId'),
$this->arrayHasKey('createTime'),
$this->arrayHasKey('createDate')
));

wei()->stat->log('test', [
'a' => 1,
]);
}
}
1 change: 1 addition & 0 deletions tests/travis.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extension="memcached.so"

0 comments on commit c50678c

Please sign in to comment.