diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..c00b116 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,11 @@ +language: python +python: + - "2.7" +before_script: + - sudo apt-get update + - sudo apt-get install php5-cli +install: + - pip install pytest + - python setup.py install +script: + - py.test diff --git a/phpy/php.py b/phpy/php.py index eda0cfc..9e90b91 100644 --- a/phpy/php.py +++ b/phpy/php.py @@ -12,8 +12,12 @@ def __init__(self, file_path): def __quote(self, arguments): for arg in arguments: - if type(arg) in (str, unicode): + if isinstance(arg, basestring): + if isinstance(arg, unicode): + arg = arg.encode('utf-8') yield '\'%s\'' % arg + elif arg is None: + yield 'NULL' else: yield str(arg) diff --git a/tests/test.php b/tests/test.php new file mode 100644 index 0000000..8dde0ce --- /dev/null +++ b/tests/test.php @@ -0,0 +1,10 @@ + $foo, + "bar" => $bar, + "baz" => $baz + ); + echo json_encode($rv); + } +?> diff --git a/tests/test_phpy.py b/tests/test_phpy.py new file mode 100644 index 0000000..d0dd359 --- /dev/null +++ b/tests/test_phpy.py @@ -0,0 +1,22 @@ +# encoding: utf-8 +import os.path +import pytest +from phpy import PHP + + +test_php_path = os.path.join(os.path.dirname(__file__), 'test.php') + + +@pytest.mark.parametrize(('foo', 'bar', 'baz'), [ + (1, 2, 3), + (0.0, 1.1, 2.2), + ('foo', 'bar', 'baz'), + (u'가', u'나', u'다'), + (None, None, None), +]) +def test_get_dict(foo, bar, baz): + php = PHP(test_php_path) + assert ( + php.get_dict('mapping', [foo, bar, baz]) == + dict(foo=foo, bar=bar, baz=baz) + )