-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Consolidate spacing in logger class * Configurable formats * Support microseconds * Remove ryan from log names * Make new logger values configurable * Update config sample with log format options * Fix null/default config handling for log formatting * Remove readme section * Basic tests for logger * Fix NS Client Logger construction
- Loading branch information
Showing
9 changed files
with
175 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ | |
.DS_Store | ||
composer.lock | ||
*.bat | ||
.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="./vendor/autoload.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
stopOnFailure="false"> | ||
<testsuites> | ||
<testsuite name="Tests"> | ||
<directory>./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist processUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">./src/</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
<?php | ||
|
||
// An example of loading your config from environment variables with optional defaults. | ||
return [ | ||
'endpoint' => getenv('NETSUITE_ENDPOINT') ?: '2021_1', | ||
'host' => getenv('NETSUITE_HOST') ?: 'https://webservices.netsuite.com', | ||
'email' => getenv('NETSUITE_EMAIL') ?: '[email protected]', | ||
'password' => getenv('NETSUITE_PASSWORD') ?: 'mySecretPwd', | ||
'role' => getenv('NETSUITE_ROLE') ?: '3', | ||
'account' => getenv('NETSUITE_ACCOUNT') ?: 'MYACCT1', | ||
'appid' => getenv('NETSUITE_APP_ID') ?: '4AD027CA-88B3-46EC-9D3E-41C6E6A325E2', | ||
'logging' => getenv('NETSUITE_LOGGING') ?: false, | ||
'log_path' => getenv('NETSUITE_LOG_PATH') ?: '', | ||
]; | ||
return array( | ||
'endpoint' => getenv('NETSUITE_ENDPOINT') ?: '2021_1', | ||
'host' => getenv('NETSUITE_HOST') ?: 'https://webservices.netsuite.com', | ||
'email' => getenv('NETSUITE_EMAIL') ?: '[email protected]', | ||
'password' => getenv('NETSUITE_PASSWORD') ?: 'mySecretPwd', | ||
'role' => getenv('NETSUITE_ROLE') ?: '3', | ||
'account' => getenv('NETSUITE_ACCOUNT') ?: 'MYACCT1', | ||
'appid' => getenv('NETSUITE_APP_ID') ?: '4AD027CA-88B3-46EC-9D3E-41C6E6A325E2', | ||
'logging' => getenv('NETSUITE_LOGGING') ?: false, | ||
'log_path' => getenv('NETSUITE_LOG_PATH') ?: '', | ||
'log_format' => getenv('NETSUITE_LOG_FORMAT') ?: 'netsuite-php-%date-%operation', | ||
'log_dateformat' => getenv('NETSUITE_LOG_DATEFORMAT') ?: 'Ymd.His.u', | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
namespace tests\Netsuite; | ||
|
||
use NetSuite\Logger; | ||
use org\bovigo\vfs\vfsStream; | ||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\PhpUnit\ProphecyTrait; | ||
|
||
/** | ||
* @coversDefault \NetSuite\Logger | ||
*/ | ||
class LoggerTest extends TestCase | ||
{ | ||
/** | ||
* @var \org\bovigo\vfs\vfsStreamDirectory | ||
*/ | ||
private $root; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->root = vfsStream::setup('/app/log'); | ||
} | ||
|
||
public function testLogSoapCall() | ||
{ | ||
$logger = new Logger('vfs://app/log/'); | ||
$logger->logSoapCall($this->getSoapClient(), 'upsert'); | ||
|
||
// Find logs in log directory. scandir() + hack because glob() doesn't support stream wrappers. | ||
$files = scandir('vfs://app/log/'); | ||
$files = array_filter($files, function (string $file) { return 0 !== strncmp($file, '.', 1); }); | ||
$this->assertCount(2, $files); | ||
|
||
// Find the date. | ||
$first = current($files); | ||
preg_match('/netsuite-php-(.*)-upsert/', $first, $matches); | ||
$this->assertNotEmpty($matches, 'Log matches format'); | ||
$timestamp = $matches[1]; | ||
|
||
$this->assertFileExists( "vfs://app/log/netsuite-php-$timestamp-upsert-request.xml"); | ||
$this->assertFileExists( "vfs://app/log/netsuite-php-$timestamp-upsert-response.xml"); | ||
$this->assertEquals(file_get_contents("vfs://app/log/netsuite-php-$timestamp-upsert-request.xml"), "<?xml version=\"1.0\"?>\n<request/>\n"); | ||
// Should this be pretty and cleaned up too? | ||
$this->assertEquals(file_get_contents("vfs://app/log/netsuite-php-$timestamp-upsert-response.xml"), "<response/>"); | ||
|
||
// @todo assert sanitization. | ||
} | ||
|
||
public function testSetPath() | ||
{ | ||
$logger = new Logger(null, 'file'); | ||
$logger->setPath($this->root->url()); | ||
$logger->logSoapCall($this->getSoapClient(), 'upsert'); | ||
$this->assertFileExists($this->root->url() . '/file-request.xml'); | ||
$this->assertFileExists($this->root->url() . '/file-response.xml'); | ||
} | ||
|
||
|
||
private function getSoapClient($request = '<request/>', $response = '<response/>') | ||
{ | ||
// This would be easier with prophecy, but it doesn't support "virtual private" methods. | ||
// @see https://github.com/phpspec/prophecy/issues/108 | ||
$client = $this->getMockBuilder(\SoapClient::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$client | ||
->method('__getLastRequest') | ||
->willReturn($request); | ||
$client | ||
->method('__getLastResponse') | ||
->willReturn($response); | ||
return $client; | ||
} | ||
|
||
} |