diff --git a/src/Bolt.php b/src/Bolt.php index 2e3c82e..0b4080c 100644 --- a/src/Bolt.php +++ b/src/Bolt.php @@ -26,18 +26,25 @@ final class Bolt public function __construct(private IConnection $connection) { - if (!file_exists(getcwd() . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR)) { - mkdir(getcwd() . DIRECTORY_SEPARATOR . 'temp'); + $_ENV['TEMP_DIR'] = getenv('TEMP') ?: getenv('TMPDIR') ?: (dirname(__DIR__) . DIRECTORY_SEPARATOR . 'temp'); + var_dump($_ENV['TEMP_DIR']); + if (!file_exists($_ENV['TEMP_DIR'])) { + mkdir($_ENV['TEMP_DIR'], recursive: true); } + if (!getenv('BOLT_ANALYTICS_OPTOUT')) { + if (!file_exists($_ENV['TEMP_DIR'] . DIRECTORY_SEPARATOR . 'php-bolt-analytics' . DIRECTORY_SEPARATOR)) { + mkdir($_ENV['TEMP_DIR'] . DIRECTORY_SEPARATOR . 'php-bolt-analytics'); + } $this->track(); } + $this->setProtocolVersions(5.4, 5, 4.4); } private function track(): void { - foreach (glob(getcwd() . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'queries.*.cnt') as $file) { + foreach (glob($_ENV['TEMP_DIR'] . DIRECTORY_SEPARATOR . 'php-bolt-analytics' . DIRECTORY_SEPARATOR . 'queries.*.cnt') as $file) { $time = intval(explode('.', basename($file))[1]); if ($time < strtotime('today')) { $count = file_get_contents($file); diff --git a/src/helpers/FileCache.php b/src/helpers/FileCache.php index 5cfcb54..bd89ffd 100644 --- a/src/helpers/FileCache.php +++ b/src/helpers/FileCache.php @@ -17,14 +17,13 @@ class FileCache implements CacheInterface public function __construct() { - $this->tempDir = getcwd() . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR; - + $this->tempDir = $_ENV['TEMP_DIR'] . DIRECTORY_SEPARATOR . 'php-bolt-filecache' . DIRECTORY_SEPARATOR; if (!file_exists($this->tempDir)) { - mkdir(rtrim($this->tempDir, DIRECTORY_SEPARATOR)); + mkdir($_ENV['TEMP_DIR'] . DIRECTORY_SEPARATOR . 'php-bolt-filecache'); } // clean old - foreach (scandir($this->tempDir . 'temp') as $file) { + foreach (scandir($this->tempDir) as $file) { if ($file == '.' || $file == '..') continue; if (filemtime($this->tempDir . $file) < strtotime('-1 hour')) diff --git a/src/protocol/AProtocol.php b/src/protocol/AProtocol.php index aca2660..aabd5c0 100644 --- a/src/protocol/AProtocol.php +++ b/src/protocol/AProtocol.php @@ -73,7 +73,7 @@ protected function write(iterable $generator): void private function track(): void { - $file = getcwd() . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'queries.' . strtotime('today') . '.cnt'; + $file = $_ENV['TEMP_DIR'] . DIRECTORY_SEPARATOR . 'php-bolt-analytics' . DIRECTORY_SEPARATOR . 'queries.' . strtotime('today') . '.cnt'; $count = file_exists($file) ? intval(file_get_contents($file)) : 0; file_put_contents($file, $count + 1); } diff --git a/tests/BoltTest.php b/tests/BoltTest.php index c7646f1..d23976a 100644 --- a/tests/BoltTest.php +++ b/tests/BoltTest.php @@ -14,7 +14,7 @@ * @link https://github.com/neo4j-php/Bolt * @package Bolt\tests */ -class BoltTest extends ATest +class BoltTest extends TestLayer { public function testSockets(): void { diff --git a/tests/PerformanceTest.php b/tests/PerformanceTest.php index e2c8807..a52a154 100644 --- a/tests/PerformanceTest.php +++ b/tests/PerformanceTest.php @@ -14,7 +14,7 @@ * @link https://github.com/neo4j-php/Bolt * @package Bolt\tests */ -class PerformanceTest extends ATest +class PerformanceTest extends TestLayer { public function test50KRecords(): void { diff --git a/tests/ATest.php b/tests/TestLayer.php similarity index 98% rename from tests/ATest.php rename to tests/TestLayer.php index a0912b4..63e0bf2 100644 --- a/tests/ATest.php +++ b/tests/TestLayer.php @@ -9,7 +9,7 @@ * Class ATest * @package Bolt\tests */ -class ATest extends \PHPUnit\Framework\TestCase +abstract class TestLayer extends \PHPUnit\Framework\TestCase { public static function setUpBeforeClass(): void { diff --git a/tests/connection/ConnectionTest.php b/tests/connection/ConnectionTest.php index a247feb..195320b 100644 --- a/tests/connection/ConnectionTest.php +++ b/tests/connection/ConnectionTest.php @@ -3,7 +3,7 @@ namespace Bolt\tests\connection; use Bolt\Bolt; -use Bolt\tests\ATest; +use Bolt\tests\TestLayer; use Bolt\connection\{ IConnection, Socket, @@ -18,7 +18,7 @@ * @link https://github.com/neo4j-php/Bolt * @package Bolt\tests\connection */ -final class ConnectionTest extends ATest +final class ConnectionTest extends TestLayer { public function provideConnections(): array { diff --git a/tests/packstream/v1/BytesTest.php b/tests/packstream/v1/BytesTest.php index a954a42..2717b1a 100644 --- a/tests/packstream/v1/BytesTest.php +++ b/tests/packstream/v1/BytesTest.php @@ -5,13 +5,13 @@ use Bolt\Bolt; use Bolt\packstream\Bytes; use Bolt\protocol\AProtocol; -use Bolt\tests\ATest; +use Bolt\tests\TestLayer; /** * Class BytesTest * @package Bolt\tests\packstream\v1 */ -class BytesTest extends ATest +class BytesTest extends TestLayer { public function testInit(): AProtocol { diff --git a/tests/packstream/v1/PackerTest.php b/tests/packstream/v1/PackerTest.php index b5a9563..1caa956 100644 --- a/tests/packstream/v1/PackerTest.php +++ b/tests/packstream/v1/PackerTest.php @@ -4,7 +4,7 @@ use Bolt\Bolt; use Bolt\protocol\AProtocol; -use Bolt\tests\ATest; +use Bolt\tests\TestLayer; /** * Class PackerTest @@ -13,7 +13,7 @@ * @link https://github.com/neo4j-php/Bolt * @package Bolt\tests\packstream\v1 */ -class PackerTest extends ATest +class PackerTest extends TestLayer { public function testInit(): AProtocol { diff --git a/tests/packstream/v1/UnpackerTest.php b/tests/packstream/v1/UnpackerTest.php index 55b9b16..a0eef2a 100644 --- a/tests/packstream/v1/UnpackerTest.php +++ b/tests/packstream/v1/UnpackerTest.php @@ -4,7 +4,7 @@ use Bolt\Bolt; use Bolt\protocol\{AProtocol, Response}; -use Bolt\tests\ATest; +use Bolt\tests\TestLayer; use Bolt\enum\Signature; /** @@ -14,7 +14,7 @@ * @link https://github.com/neo4j-php/Bolt * @package Bolt\tests\packstream\v1 */ -class UnpackerTest extends ATest +class UnpackerTest extends TestLayer { public function testInit(): AProtocol { diff --git a/tests/protocol/ATest.php b/tests/protocol/ProtocolLayer.php similarity index 86% rename from tests/protocol/ATest.php rename to tests/protocol/ProtocolLayer.php index a0c87af..8bbb68c 100644 --- a/tests/protocol/ATest.php +++ b/tests/protocol/ProtocolLayer.php @@ -14,7 +14,7 @@ * @link https://github.com/neo4j-php/Bolt * @package Bolt\tests */ -abstract class ATest extends TestCase +abstract class ProtocolLayer extends TestCase { /** * @var string Temporal buffer for packed message to be read @@ -100,8 +100,15 @@ public function readCallback(int $length = 2048): string */ protected function setUp(): void { - if (!file_exists(getcwd() . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR)) { - mkdir(getcwd() . DIRECTORY_SEPARATOR . 'temp'); + $_ENV['TEMP_DIR'] = getenv('TEMP') ?: getenv('TMPDIR') ?: (dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'temp'); + if (!file_exists($_ENV['TEMP_DIR'])) { + mkdir($_ENV['TEMP_DIR'], recursive: true); + } + + if (!getenv('BOLT_ANALYTICS_OPTOUT')) { + if (!file_exists($_ENV['TEMP_DIR'] . DIRECTORY_SEPARATOR . 'php-bolt-analytics' . DIRECTORY_SEPARATOR)) { + mkdir($_ENV['TEMP_DIR'] . DIRECTORY_SEPARATOR . 'php-bolt-analytics'); + } } self::$readBuffer = ''; diff --git a/tests/protocol/V1Test.php b/tests/protocol/V1Test.php index 8de674d..1edd565 100644 --- a/tests/protocol/V1Test.php +++ b/tests/protocol/V1Test.php @@ -12,7 +12,7 @@ * @link https://github.com/neo4j-php/Bolt * @package Bolt\tests\protocol */ -class V1Test extends ATest +class V1Test extends ProtocolLayer { public function test__construct(): V1 { diff --git a/tests/protocol/V2Test.php b/tests/protocol/V2Test.php index cb55f05..02b6624 100644 --- a/tests/protocol/V2Test.php +++ b/tests/protocol/V2Test.php @@ -12,7 +12,7 @@ * @link https://github.com/neo4j-php/Bolt * @package Bolt\tests\protocol */ -class V2Test extends ATest +class V2Test extends ProtocolLayer { public function test__construct(): V2 { diff --git a/tests/protocol/V3Test.php b/tests/protocol/V3Test.php index 38dea6b..75841ef 100644 --- a/tests/protocol/V3Test.php +++ b/tests/protocol/V3Test.php @@ -12,7 +12,7 @@ * @link https://github.com/neo4j-php/Bolt * @package Bolt\tests\protocol */ -class V3Test extends ATest +class V3Test extends ProtocolLayer { public function test__construct(): V3 { diff --git a/tests/protocol/V4Test.php b/tests/protocol/V4Test.php index c4326b5..1c5aeb9 100644 --- a/tests/protocol/V4Test.php +++ b/tests/protocol/V4Test.php @@ -12,7 +12,7 @@ * @link https://github.com/neo4j-php/Bolt * @package Bolt\tests\protocol */ -class V4Test extends ATest +class V4Test extends ProtocolLayer { public function test__construct(): V4 { diff --git a/tests/protocol/V4_1Test.php b/tests/protocol/V4_1Test.php index fc8b8cf..b7d5413 100644 --- a/tests/protocol/V4_1Test.php +++ b/tests/protocol/V4_1Test.php @@ -12,7 +12,7 @@ * @link https://github.com/neo4j-php/Bolt * @package Bolt\tests\protocol */ -class V4_1Test extends ATest +class V4_1Test extends ProtocolLayer { public function test__construct(): V4_1 { diff --git a/tests/protocol/V4_2Test.php b/tests/protocol/V4_2Test.php index 0e761db..a112e34 100644 --- a/tests/protocol/V4_2Test.php +++ b/tests/protocol/V4_2Test.php @@ -3,7 +3,6 @@ namespace Bolt\tests\protocol; use Bolt\protocol\V4_2; -use Bolt\packstream\v1\{Packer, Unpacker}; /** * Class V4_2Test @@ -12,7 +11,7 @@ * @link https://github.com/neo4j-php/Bolt * @package Bolt\tests\protocol */ -class V4_2Test extends ATest +class V4_2Test extends ProtocolLayer { public function test__construct(): V4_2 { diff --git a/tests/protocol/V4_3Test.php b/tests/protocol/V4_3Test.php index 3fef831..01e9b34 100644 --- a/tests/protocol/V4_3Test.php +++ b/tests/protocol/V4_3Test.php @@ -12,7 +12,7 @@ * @link https://github.com/neo4j-php/Bolt * @package Bolt\tests\protocol */ -class V4_3Test extends ATest +class V4_3Test extends ProtocolLayer { public function test__construct(): V4_3 { diff --git a/tests/protocol/V4_4Test.php b/tests/protocol/V4_4Test.php index 9c1e467..eaa6515 100644 --- a/tests/protocol/V4_4Test.php +++ b/tests/protocol/V4_4Test.php @@ -12,7 +12,7 @@ * @link https://github.com/neo4j-php/Bolt * @package Bolt\tests\protocol */ -class V4_4Test extends ATest +class V4_4Test extends ProtocolLayer { public function test__construct(): V4_4 { diff --git a/tests/protocol/V5Test.php b/tests/protocol/V5Test.php index d018ab3..274bd92 100644 --- a/tests/protocol/V5Test.php +++ b/tests/protocol/V5Test.php @@ -3,7 +3,6 @@ namespace Bolt\tests\protocol; use Bolt\protocol\V5; -use Bolt\packstream\v1\{Packer, Unpacker}; /** * Class V5Test @@ -12,7 +11,7 @@ * @link https://github.com/neo4j-php/Bolt * @package Bolt\tests\protocol */ -class V5Test extends ATest +class V5Test extends ProtocolLayer { public function test__construct(): V5 { diff --git a/tests/protocol/V5_1Test.php b/tests/protocol/V5_1Test.php index c5d5395..7941d2e 100644 --- a/tests/protocol/V5_1Test.php +++ b/tests/protocol/V5_1Test.php @@ -12,7 +12,7 @@ * @link https://github.com/neo4j-php/Bolt * @package Bolt\tests\protocol */ -class V5_1Test extends \Bolt\tests\protocol\ATest +class V5_1Test extends \Bolt\tests\protocol\ProtocolLayer { public function test__construct(): V5_1 { diff --git a/tests/protocol/V5_2Test.php b/tests/protocol/V5_2Test.php index fb23fb5..d82d220 100644 --- a/tests/protocol/V5_2Test.php +++ b/tests/protocol/V5_2Test.php @@ -9,7 +9,7 @@ * @link https://github.com/neo4j-php/Bolt * @package Bolt\tests\protocol */ -class V5_2Test extends \Bolt\tests\protocol\ATest +class V5_2Test extends \Bolt\tests\protocol\ProtocolLayer { public function test__construct(): V5_2 { diff --git a/tests/protocol/V5_3Test.php b/tests/protocol/V5_3Test.php index c4bb26a..cef5245 100644 --- a/tests/protocol/V5_3Test.php +++ b/tests/protocol/V5_3Test.php @@ -12,7 +12,7 @@ * @link https://github.com/neo4j-php/Bolt * @package Bolt\tests\protocol */ -class V5_3Test extends \Bolt\tests\protocol\ATest +class V5_3Test extends \Bolt\tests\protocol\ProtocolLayer { public function test__construct(): V5_3 { diff --git a/tests/protocol/V5_4Test.php b/tests/protocol/V5_4Test.php index 0f4ca40..bb6d179 100644 --- a/tests/protocol/V5_4Test.php +++ b/tests/protocol/V5_4Test.php @@ -9,7 +9,7 @@ * @link https://github.com/neo4j-php/Bolt * @package Bolt\tests\protocol */ -class V5_4Test extends \Bolt\tests\protocol\ATest +class V5_4Test extends \Bolt\tests\protocol\ProtocolLayer { public function test__construct(): V5_4 { diff --git a/tests/structures/AStructures.php b/tests/structures/StructureLayer.php similarity index 95% rename from tests/structures/AStructures.php rename to tests/structures/StructureLayer.php index c99ac96..aefd866 100644 --- a/tests/structures/AStructures.php +++ b/tests/structures/StructureLayer.php @@ -2,7 +2,7 @@ namespace Bolt\tests\structures; -use Bolt\tests\ATest; +use Bolt\tests\TestLayer; use Exception; /** @@ -11,7 +11,7 @@ * @link https://github.com/neo4j-php/Bolt * @package Bolt\tests\protocol */ -class AStructures extends ATest +class StructureLayer extends TestLayer { /** * How many iterations do for each date/time test diff --git a/tests/structures/v1/StructuresTest.php b/tests/structures/v1/StructuresTest.php index 874684d..6753521 100644 --- a/tests/structures/v1/StructuresTest.php +++ b/tests/structures/v1/StructuresTest.php @@ -34,7 +34,7 @@ * @link https://github.com/neo4j-php/Bolt * @package Bolt\tests */ -class StructuresTest extends \Bolt\tests\structures\AStructures +class StructuresTest extends \Bolt\tests\structures\StructureLayer { public function testInit(): AProtocol|V4_4|V4_3|V4_2|V3 { diff --git a/tests/structures/v4_3/StructuresTest.php b/tests/structures/v4_3/StructuresTest.php index b8afd62..573beb2 100644 --- a/tests/structures/v4_3/StructuresTest.php +++ b/tests/structures/v4_3/StructuresTest.php @@ -26,7 +26,7 @@ * @link https://github.com/neo4j-php/Bolt * @package Bolt\tests\protocol\v4_3 */ -class StructuresTest extends \Bolt\tests\structures\AStructures +class StructuresTest extends \Bolt\tests\structures\StructureLayer { public function testInit(): AProtocol|V4_4|V4_3 { diff --git a/tests/structures/v5/StructuresTest.php b/tests/structures/v5/StructuresTest.php index 762be31..0d262e3 100644 --- a/tests/structures/v5/StructuresTest.php +++ b/tests/structures/v5/StructuresTest.php @@ -22,7 +22,7 @@ * @link https://github.com/neo4j-php/Bolt * @package Bolt\tests\protocol\v5 */ -class StructuresTest extends \Bolt\tests\structures\AStructures +class StructuresTest extends \Bolt\tests\structures\StructureLayer { public function testInit(): AProtocol|V4_3|V4_4|V5|V5_1 {