From 612cfc2035fdd49c2a9569309777d7bb367abae8 Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Sun, 15 Apr 2018 20:31:35 +0200 Subject: [PATCH] Bugfixed SharedMemoryBlock, added tests --- src/Shm/SharedMemoryBlock.php | 2 +- tests/Shm/SharedMemoryBlockTest.php | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tests/Shm/SharedMemoryBlockTest.php diff --git a/src/Shm/SharedMemoryBlock.php b/src/Shm/SharedMemoryBlock.php index ec23762..63803b6 100644 --- a/src/Shm/SharedMemoryBlock.php +++ b/src/Shm/SharedMemoryBlock.php @@ -29,7 +29,7 @@ class SharedMemoryBlock */ public function __construct(KeyInterface $key, string $flags, int $memsize, int $perm = 0666) { - if (!($shm_resource = shmop_open($key->getKey(), $memsize, $perm))) { + if (!($shm_resource = shmop_open($key->getKey(), $flags, $perm, $memsize))) { throw new \RuntimeException("Unable to attach shm resource {$key}"); } diff --git a/tests/Shm/SharedMemoryBlockTest.php b/tests/Shm/SharedMemoryBlockTest.php new file mode 100644 index 0000000..a1b794a --- /dev/null +++ b/tests/Shm/SharedMemoryBlockTest.php @@ -0,0 +1,25 @@ +assertEquals(11, $shm->write("Hello World", 0)); + $this->assertEquals("Hello World", $shm->read(11, 0)); + $this->assertEquals(3, $shm->write("foo", 2)); + $this->assertEquals("Hefoo World", $shm->read(11, 0)); + + $shm->destroy(); + } +} \ No newline at end of file