0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[PHP] Travis CI で memcached を使う

Posted at

Travis CI で memcached を使う方法を調べました。

ドキュメントによると memcached はインストールされているもののサービスは起動していないので、.travis.ymlservicesmemcached を指定する必要があるとのことです。また、PHP から memcached を利用するために php5-memcached のインストールと php.ini に memcached.so を読み込むように設定を追記します。php.ini への追記は phpenv config-add コマンドによって実現できました。travis.php.ini の内容が php.ini へ反映されます。

.travis.yml
language: php
services:
  - memcached
before_script:
  - "sudo apt-get install php5-memcached"
  - "phpenv config-add travis.php.ini"
script:
  - phpunit MemcachedTest.php
travis.php.ini
extension=memcached.so

PHP から memcached を使えるか確かめるテストです。

MemcachedTest.php
<?php

class MemcachedTest extends PHPUnit_Framework_TestCase{
  function testMemcached(){
    $m = new Memcached();
    $m->addServer('localhost', 11211);
    $m->add('name', 'yamada');
    $this->assertEquals('yamada', $m->get('name'));
  }
}

テストはパスしました。

$ phpunit MemcachedTest.php
PHPUnit 4.3.4 by Sebastian Bergmann.
.
Time: 64 ms, Memory: 3.75Mb
OK (1 test, 1 assertion)

GitHub
https://github.com/suzuki86/sample-of-using-memcached-on-travisci

Travis CI
https://travis-ci.org/suzuki86/sample-of-using-memcached-on-travisci

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?