Skip to content

Commit

Permalink
Feature/hhvm 4.0 (#8)
Browse files Browse the repository at this point in the history
* for travis
  • Loading branch information
ytake authored Apr 15, 2019
1 parent acef4f9 commit aae89f5
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 34 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
/tests/ export-ignore
/.hhconfig export-ignore
hhast-lint.json export-ignore
docker-compose.yml
/docker
15 changes: 0 additions & 15 deletions .travis.sh

This file was deleted.

28 changes: 20 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 20 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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"
9 changes: 9 additions & 0 deletions docker/hhvm/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions src/Driver/FileSystemCache.hack
Original file line number Diff line number Diff line change
Expand Up @@ -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>>
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/MapCache.hack
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MapCache extends CacheProvider {
return $element->getData();
}
}
return;
return null;
}

<<__Override>>
Expand Down
6 changes: 3 additions & 3 deletions src/Driver/MemcachedCache.hack
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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>>
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/VoidCache.hack
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class VoidCache extends CacheProvider {

<<__Override>>
public function fetch(string $_id): mixed {
return;
return null;
}

<<__Override>>
Expand Down
2 changes: 1 addition & 1 deletion tests/CacheManagerTest.hack
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ final class CacheManagerTest extends HackTest {
class NullCache extends CacheProvider {
<<__Override>>
public function fetch(string $_id): mixed {
return;
return null;
}

<<__Override>>
Expand Down
6 changes: 5 additions & 1 deletion tests/Driver/MemcachedCacheTest.hack
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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));
Expand Down

0 comments on commit aae89f5

Please sign in to comment.