Skip to content

Commit c3ae548

Browse files
committed
Menambahkan UnitTest
1 parent 01a33bb commit c3ae548

File tree

8 files changed

+179
-23
lines changed

8 files changed

+179
-23
lines changed

.styleci.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
preset: laravel
2+
3+
enabled:
4+
- is_null
5+
- no_useless_else
6+
- phpdoc_order
7+
- phpdoc_separation
8+
- unalign_double_arrow
9+
10+
linting: true

.travis.yml

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,41 @@ env:
1212

1313
matrix:
1414
include:
15-
- php: 5.4
1615
- php: 5.5
16+
env: LARAVEL_VERSION=5.2.*
17+
- php: 5.5
18+
env: LARAVEL_VERSION=5.3.*
19+
- php: 5.5
20+
env: LARAVEL_VERSION=5.4.*
21+
- php: 5.6
22+
env: LARAVEL_VERSION=5.2.*
23+
- php: 5.6
24+
env: LARAVEL_VERSION=5.2.*
25+
- php: 5.6
26+
env: LARAVEL_VERSION=5.3.*
1727
- php: 5.6
28+
env: LARAVEL_VERSION=5.4.*
1829
- php: hhvm
1930
env: XDEBUG=1
2031
- php: 7.0
21-
env: COVERAGE=1 XDEBUG=1
32+
env: COVERAGE=1 XDEBUG=1 LARAVEL_VERSION=5.4.*
2233
- php: 7.1
23-
env: COVERAGE=1 XDEBUG=1
34+
env: COVERAGE=1 XDEBUG=1 LARAVEL_VERSION=5.4.*
2435
- php: 7.2
25-
env: COVERAGE=1 XDEBUG=1
36+
env: COVERAGE=1 XDEBUG=1 LARAVEL_VERSION=5.4.*
2637
fast_finish: true
2738
allow_failures:
2839
- php: 7.0
2940
- php: 7.1
3041
- php: 7.2
3142

32-
before_script:
43+
install:
3344
- travis_retry composer self-update
34-
- travis_retry composer install --no-interaction --prefer-source --dev
45+
- travis_retry composer require "laravel/framework:${LARAVEL_VERSION}" --no-update -n
3546

3647
script:
37-
- composer test:ci
48+
- if [ "$TRAVIS_PHP_VERSION" != "7.0" ]; then vendor/bin/phpunit; fi
49+
- if [ "$TRAVIS_PHP_VERSION" == "7.0" ]; then vendor/bin/phpunit --coverage-clover build/logs/clover.xml; fi
3850

3951
after_success:
4052
bash <(curl -s https://codecov.io/bash)

codecov.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Run this to validate this file:
2+
# curl --data-binary @codecov.yml https://codecov.io/validate
3+
coverage:
4+
precision: 5
5+
round: down
6+
status:
7+
project:
8+
default:
9+
target: auto
10+
if_no_uploads: error
11+
patch:
12+
default:
13+
if_no_uploads: error
14+
changes: true
15+
comment: true

phpunit.xml.dist

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,19 @@
1919
<directory suffix="Test.php">./tests</directory>
2020
</testsuite>
2121
</testsuites>
22+
2223
<filter>
2324
<whitelist processUncoveredFilesFromWhitelist="true">
2425
<directory suffix=".php">./src</directory>
2526
</whitelist>
2627
</filter>
28+
29+
<logging>
30+
<log type="tap" target="build/report.tap"/>
31+
<log type="junit" target="build/report.junit.xml"/>
32+
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
33+
<log type="coverage-text" target="build/coverage.txt"/>
34+
<log type="coverage-clover" target="build/logs/clover.xml"/>
35+
</logging>
36+
2737
</phpunit>

tests/AbstractTestCase.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
use GrahamCampbell\TestBench\AbstractPackageTestCase;
66
use Odenktools\Bca\BcaServiceProvider;
77

8+
/**
9+
* BCA unit test class.
10+
*
11+
* @author Pribumi Technology
12+
* @license MIT
13+
* @copyright (c) 2017, Pribumi Technology
14+
*/
815
abstract class AbstractTestCase extends AbstractPackageTestCase
916
{
1017
/**
@@ -18,4 +25,4 @@ protected function getServiceProviderClass($app)
1825
{
1926
return BcaServiceProvider::class;
2027
}
21-
}
28+
}

tests/BcaFactoryTest.php

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
<?php
22

3-
declare (strict_types = 1);
4-
53
namespace Odenktools\Tests\Bca;
64

5+
use Bca\BcaHttp;
76
use Odenktools\Bca;
87
use Odenktools\Bca\BcaFactory;
98

9+
/**
10+
* BCA factory provider test class.
11+
*
12+
* @author Pribumi Technology
13+
* @license MIT
14+
* @copyright (c) 2017, Pribumi Technology
15+
*/
1016
class BcaFactoryTest extends AbstractTestCase
1117
{
1218
public function testMakeStandard()
@@ -27,8 +33,7 @@ public function testMakeStandard()
2733
'port' => 443,
2834
'timeout' => 30,
2935
]);
30-
31-
$this->assertInstanceOf(Bca::class, $return);
36+
$this->assertInstanceOf(BcaHttp::class, $return);
3237
}
3338

3439
/**
@@ -83,17 +88,17 @@ public function testMakeWithoutSecret()
8388
$factory = $this->getBcaFactory();
8489

8590
$factory->make([
86-
'corp_id' => 'your-corp_id',
87-
'client_id' => 'your-client_id',
88-
'api_key' => 'your-api_key',
89-
'secret_key' => 'your-secret_key',
90-
'timezone' => 'Asia/Jakarta',
91-
'host' => 'sandbox.bca.co.id',
92-
'scheme' => 'https',
93-
'development' => true,
94-
'options' => [],
95-
'port' => 443,
96-
'timeout' => 30,
91+
'corp_id' => 'your-corp_id',
92+
'client_id' => 'your-client_id',
93+
'api_key' => 'your-api_key',
94+
'secret_key' => 'your-secret_key',
95+
'timezone' => 'Asia/Jakarta',
96+
'host' => 'sandbox.bca.co.id',
97+
'scheme' => 'https',
98+
'development' => true,
99+
'options' => [],
100+
'port' => 443,
101+
'timeout' => 30,
97102
]);
98103
}
99104

tests/BcaManagerTest.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace Odenktools\Tests\Bca;
4+
5+
use Bca\BcaHttp;
6+
use Illuminate\Contracts\Config\Repository;
7+
use Mockery;
8+
use Odenktools\Bca;
9+
use Odenktools\Bca\BcaFactory;
10+
use Odenktools\Bca\BcaManager;
11+
12+
/**
13+
* BCA manager test class.
14+
*
15+
* @author Pribumi Technology
16+
* @license MIT
17+
* @copyright (c) 2017, Pribumi Technology
18+
*/
19+
class BcaManagerTest extends AbstractTestCase
20+
{
21+
public function testCreateConnection()
22+
{
23+
$config = ['path' => __DIR__];
24+
25+
$manager = $this->getManager($config);
26+
27+
$manager->getConfig()->shouldReceive('get')->once()
28+
->with('bca.default')->andReturn('bca');
29+
30+
$this->assertSame([], $manager->getConnections());
31+
32+
$return = $manager->connection();
33+
34+
$this->assertInstanceOf(BcaHttp::class, $return);
35+
36+
$this->assertArrayHasKey('bca', $manager->getConnections());
37+
}
38+
39+
protected function getManager(array $config)
40+
{
41+
$repository = Mockery::mock(Repository::class);
42+
43+
$factory = Mockery::mock(BcaFactory::class);
44+
45+
$manager = new BcaManager($repository, $factory);
46+
47+
$manager->getConfig()->shouldReceive('get')->once()
48+
->with('bca.connections')->andReturn(['bca' => $config]);
49+
50+
$config['name'] = 'bca';
51+
52+
$manager->getFactory()->shouldReceive('make')->once()
53+
->with($config)->andReturn(Mockery::mock(BcaHttp::class));
54+
55+
return $manager;
56+
}
57+
}

tests/ServiceProviderTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Odenktools\Tests\Bca;
4+
5+
use Bca\BcaHttp;
6+
use GrahamCampbell\TestBenchCore\ServiceProviderTrait;
7+
use Odenktools\Bca\BcaFactory;
8+
use Odenktools\Bca\BcaManager;
9+
10+
/**
11+
* BCA service provider test class.
12+
*
13+
* @author Pribumi Technology
14+
* @license MIT
15+
* @copyright (c) 2017, Pribumi Technology
16+
*/
17+
class ServiceProviderTest extends AbstractTestCase
18+
{
19+
use ServiceProviderTrait;
20+
21+
public function testPusherFactoryIsInjectable()
22+
{
23+
$this->assertIsInjectable(BcaFactory::class);
24+
}
25+
26+
public function testPusherManagerIsInjectable()
27+
{
28+
$this->assertIsInjectable(BcaManager::class);
29+
}
30+
31+
public function testBindings()
32+
{
33+
$this->assertIsInjectable(BcaHttp::class);
34+
$original = $this->app['bca.connection'];
35+
$this->app['bca']->reconnect();
36+
$new = $this->app['bca.connection'];
37+
$this->assertNotSame($original, $new);
38+
$this->assertEquals($original, $new);
39+
}
40+
}

0 commit comments

Comments
 (0)