Skip to content

Commit 68c1883

Browse files
authored
Merge pull request #2 from movemove-io/Feature/Tests
Feature/tests
2 parents b39e81e + 0cb9083 commit 68c1883

12 files changed

+1003
-23
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
composer.lock
2+
*.cache
3+
vendor

.travis.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
11
language: php
22

33
php:
4-
- 5.6
5-
- 7.1
6-
- 7.2
74
- 7.3
85
- 7.4
96

107
env:
11-
- LARAVEL_VERSION=5.6.*
12-
- LARAVEL_VERSION=5.7.*
13-
- LARAVEL_VERSION=5.8.*
14-
- LARAVEL_VERSION=6.*
158
- LARAVEL_VERSION=7.*
169
- LARAVEL_VERSION=8.*
1710

1811
matrix:
1912
fast_finish: true
2013

2114
before_script:
22-
- composer update
15+
- composer install
2316

2417
script:
2518
- phpunit

composer.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,16 @@
1919
},
2020
"autoload-dev": {
2121
"psr-4": {
22-
"MoveMoveIo\\DaData\\Tests": "tests/"
22+
"MoveMoveIo\\DaData\\Tests\\": "tests/"
2323
}
2424
},
25-
"require": {}
25+
"require": {
26+
"php": "^7.2.5",
27+
"illuminate/support": "^8.8.0",
28+
"guzzlehttp/guzzle": "^7.0"
29+
},
30+
"require-dev": {
31+
"phpunit/phpunit": "^9.4.0",
32+
"orchestra/testbench": "^6.2.0"
33+
}
2634
}

config/dadata.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
<?php
22

3+
/**
4+
* Copyright (c) Dmitry Kovalev.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*
9+
* @see https://github.com/movemove-io/laravel-dadata
10+
*/
311
return [
412
/*
513
|--------------------------------------------------------------------------

phpunit.xml.dist

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="vendor/autoload.php"
3+
backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
verbose="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
processIsolation="false"
11+
stopOnFailure="false">
12+
<testsuites>
13+
<testsuite name="Test Suite">
14+
<directory>tests</directory>
15+
</testsuite>
16+
</testsuites>
17+
<filter>
18+
<whitelist>
19+
<directory suffix=".php">src/</directory>
20+
</whitelist>
21+
</filter>
22+
<php>
23+
<env name="DADATA_TOKEN" value="c21c38ebaf520082d64516fbe041d2a8a6d4211f"/>
24+
<env name="DADATA_SECRET" value="adccd63ac28701442e26b7eef57eb5eb0a72143e"/>
25+
</php>
26+
</phpunit>

src/DaDataAddressService.php renamed to src/DaDataAddress.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
use MoveMoveIo\DaData\Enums\Language;
66

77
/**
8-
* Class DaDataAddressService
8+
* Class DaDataAddress
99
* @package MoveMoveIo\DaData
1010
*/
11-
class DaDataAddressService extends DaDataService
11+
class DaDataAddress extends DaDataService
1212
{
1313

1414
/**
@@ -73,13 +73,13 @@ public function prompt(
7373
*
7474
* Returns all information about the address by coordinates.
7575
* Works for homes, streets and cities.
76-
*
7776
* @param float $lat
7877
* @param float $lon
7978
* @param int $count
8079
* @param int $radius_meters
8180
* @param int $language
8281
* @return array
82+
* @throws \Exception
8383
*/
8484
public function geolocate(
8585
float $lat,

src/DaDataService.php

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,39 @@ class DaDataService
4242
*/
4343
public function __construct()
4444
{
45-
$this->token = config('dadata.token');
46-
$this->secret = config('dadata.secret');
47-
$this->timeout = config('dadata.timeout');
45+
if (file_exists(config_path() . '/dadata.php')) {
46+
$this->token = config('dadata.token');
47+
$this->secret = config('dadata.secret');
48+
$this->timeout = config('dadata.timeout');
49+
} else {
50+
$this->token = env('DADATA_TOKEN', null);
51+
$this->secret = env('DADATA_SECRET', null);
52+
$this->timeout = env('DADATA_TIMEOUT', 10);
53+
}
54+
}
55+
56+
/**
57+
* @return string|null
58+
*/
59+
public function getToken() : ?string
60+
{
61+
return $this->token;
62+
}
63+
64+
/**
65+
* @return string|null
66+
*/
67+
public function getSecret() : ?string
68+
{
69+
return $this->secret;
70+
}
71+
72+
/**
73+
* @return int|null
74+
*/
75+
public function getTimeout() : ?int
76+
{
77+
return $this->timeout;
4878
}
4979

5080
/**

src/DaDataServiceProvider.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ class DaDataServiceProvider extends ServiceProvider
1818
*/
1919
public function register()
2020
{
21-
$this->app->bind('da_data_address', function () {
22-
return new DaDataAddressService();
21+
$this->app->singleton('da_data_address', function () {
22+
return new DaDataAddress();
2323
});
24+
25+
$this->app->alias('da_data_address', DaDataAddress::class);
2426
}
2527

2628
/**

src/Facades/DaDataAddress.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@
1010
*/
1111
class DaDataAddress extends Facade
1212
{
13-
1413
/**
1514
* Get the registered name of the component.
1615
*
1716
* @return string
1817
*/
19-
protected static function getFacadeAccessor() : string
18+
protected static function getFacadeAccessor()
2019
{
2120
return 'da_data_address';
2221
}
23-
2422
}
23+

src/Providers/CleanerDaDataProvider.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,4 @@ public function post(string $method, array $data = []) : array
7676
return $this->postData($headers, $url, $data, $this->timeout);
7777
}
7878

79-
80-
8179
}

0 commit comments

Comments
 (0)