diff --git a/.gitattributes b/.gitattributes index 9cc65b8..92f05f4 100755 --- a/.gitattributes +++ b/.gitattributes @@ -6,3 +6,5 @@ /tests/ export-ignore /.hhconfig export-ignore hhast-lint.json export-ignore +docker-compose.yml +/docker diff --git a/.travis.sh b/.travis.sh deleted file mode 100755 index 66990e9..0000000 --- a/.travis.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash -set -ex -apt update -y -DEBIAN_FRONTEND=noninteractive apt install -y php-cli zip unzip -hhvm --version -php --version - -( - cd $(mktemp -d) - curl https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer -) -composer install -hh_client - -hhvm ./vendor/bin/hacktest tests/ diff --git a/.travis.yml b/.travis.yml index f13c2b9..6ff3ca6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,13 +3,25 @@ language: generic services: - docker env: + global: + - DOCKER_COMPOSE_VERSION=1.23.2 matrix: - - HHVM_VERSION=4.0.0 - - HHVM_VERSION=4.0.1 - - HHVM_VERSION=4.0.2 - - HHVM_VERSION=4.0.3 - - HHVM_VERSION=latest -install: - - docker pull hhvm/hhvm:$HHVM_VERSION + - HHVM_VERSION=4.0.0 + - HHVM_VERSION=4.0.1 + - HHVM_VERSION=4.0.2 + - HHVM_VERSION=4.0.3 + - HHVM_VERSION=4.1.0 + - HHVM_VERSION=latest + +before_install: + - sudo rm /usr/local/bin/docker-compose + - curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose + - chmod +x docker-compose + - sudo mv docker-compose /usr/local/bin + - docker-compose build + - docker-compose up -d script: - - docker run --rm -w /var/source -v $(pwd):/var/source hhvm/hhvm:$HHVM_VERSION ./.travis.sh + - docker-compose exec hhvm /bin/bash -c 'cd /var/source && composer update' + - docker-compose exec hhvm /bin/bash -c 'cd /var/source && hh_client && hhvm ./vendor/bin/hacktest.hack tests/' +matrix: + fast_finish: true diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..c18194c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,20 @@ +version: '3' +services: + hhvm: + build: + context: ./docker/hhvm + args: + hhvmversion: ${HHVM_VERSION} + volumes: + - .:/var/source + command: hhvm --mode server -vServer.AllowRunAsRoot=1 + restart: always + tty: true + redis: + image: redis:4-alpine3.8 + ports: + - "6379:6379" + memcached: + image: memcached:latest + ports: + - "31211:11211" diff --git a/docker/hhvm/Dockerfile b/docker/hhvm/Dockerfile new file mode 100644 index 0000000..8e4ee2d --- /dev/null +++ b/docker/hhvm/Dockerfile @@ -0,0 +1,9 @@ +ARG hhvmversion +FROM "hhvm/hhvm:$hhvmversion" + +RUN apt-get update +RUN DEBIAN_FRONTEND=noninteractive +RUN apt install -y php-cli zip unzip dnsutils iputils-ping net-tools +RUN hhvm --version && php --version +RUN cd $(mktemp -d) \ + && curl https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer diff --git a/src/Driver/FileSystemCache.hack b/src/Driver/FileSystemCache.hack index 6dc4226..e120bde 100644 --- a/src/Driver/FileSystemCache.hack +++ b/src/Driver/FileSystemCache.hack @@ -40,18 +40,18 @@ class FileSystemCache extends CacheProvider { public function fetch(string $id): mixed { $resource = $this->fileContains($id); if($resource === false) { - return; + return null; } if ($resource is string) { $element = $this->unserializeElement($resource); $expiration = $element->getLifetime(); if ($expiration && $expiration < time()) { $this->delete($id); - return; + return null; } return $element->getData(); } - return; + return null; } <<__Override>> @@ -164,7 +164,7 @@ class FileSystemCache extends CacheProvider { <<__Memoize>> protected function unserializeElement(string $resource): Element { $element = \unserialize($resource); - if($element instanceof Element) { + if($element is Element) { return $element; } return new Element('', -1); diff --git a/src/Driver/MapCache.hack b/src/Driver/MapCache.hack index 74cf249..a045548 100644 --- a/src/Driver/MapCache.hack +++ b/src/Driver/MapCache.hack @@ -30,7 +30,7 @@ class MapCache extends CacheProvider { return $element->getData(); } } - return; + return null; } <<__Override>> diff --git a/src/Driver/MemcachedCache.hack b/src/Driver/MemcachedCache.hack index 5bdd1a1..ba49a91 100644 --- a/src/Driver/MemcachedCache.hack +++ b/src/Driver/MemcachedCache.hack @@ -30,7 +30,7 @@ class MemcachedCache extends CacheProvider { public function getMemcached(): Memcached { invariant( - $this->memcached instanceof Memcached, + $this->memcached is Memcached, "Type mismatch" ); return $this->memcached; @@ -39,10 +39,10 @@ class MemcachedCache extends CacheProvider { <<__Override>> public function fetch(string $id): mixed { $element = $this->getMemcached()->get($id); - if($element instanceof Element) { + if($element is Element) { return $element->getData(); } - return; + return null; } <<__Override>> diff --git a/src/Driver/VoidCache.hack b/src/Driver/VoidCache.hack index 0897707..87839da 100644 --- a/src/Driver/VoidCache.hack +++ b/src/Driver/VoidCache.hack @@ -22,7 +22,7 @@ class VoidCache extends CacheProvider { <<__Override>> public function fetch(string $_id): mixed { - return; + return null; } <<__Override>> diff --git a/tests/CacheManagerTest.hack b/tests/CacheManagerTest.hack index ef74a7a..f9436ab 100644 --- a/tests/CacheManagerTest.hack +++ b/tests/CacheManagerTest.hack @@ -36,7 +36,7 @@ final class CacheManagerTest extends HackTest { class NullCache extends CacheProvider { <<__Override>> public function fetch(string $_id): mixed { - return; + return null; } <<__Override>> diff --git a/tests/Driver/MemcachedCacheTest.hack b/tests/Driver/MemcachedCacheTest.hack index 0ebd69a..f38712c 100644 --- a/tests/Driver/MemcachedCacheTest.hack +++ b/tests/Driver/MemcachedCacheTest.hack @@ -8,6 +8,10 @@ class MemcachedCacheTest extends HackTest { public function testFetchShouldReturnNull(): void { expect(() ==> { $cache = new MemcachedCache(); + $mc = new Memcached('mc'); + $mc->addServers(array( + ['memcached', 31211], + )); expect($cache->fetch("qwerty"))->toBeNull(); })->toThrow(\HH\InvariantException::class); } @@ -16,7 +20,7 @@ class MemcachedCacheTest extends HackTest { $cache = new MemcachedCache(); $mc = new Memcached('mc'); $mc->addServers(array( - ['127.0.0.1', 11211], + ['memcached', 31211], )); $cache->setMemcached($mc); $cache->save("qwerty", new Element('testing:cache', 0));