From 6e70186496505153b42d366b7d8d684543a95245 Mon Sep 17 00:00:00 2001 From: Chaos Golubitsky Date: Thu, 8 Nov 2018 15:34:40 -0500 Subject: [PATCH] Upgrade buttonweavers site to Ubuntu Xenial --- .circleci/config.yml | 30 ++++++----- deploy/circleci/manifests/init.pp | 2 - deploy/vagrant/Vagrantfile | 9 ++-- deploy/vagrant/manifests/init.pp | 4 +- .../vagrant/modules/apache/manifests/init.pp | 26 ++++++---- .../modules/apache/templates/site_default.erb | 20 ++++++++ deploy/vagrant/modules/apt/manifests/init.pp | 14 +++++ .../modules/apt/templates/10periodic.erb | 9 ++++ .../modules/buttonmen/manifests/init.pp | 4 +- .../buttonmen/templates/phpunit.php.erb | 2 +- .../templates/run_buttonmen_tests.erb | 2 +- .../modules/javascript/manifests/init.pp | 11 +++- .../templates/install_phantomjs.erb | 13 +++++ .../vagrant/modules/mysql/manifests/init.pp | 18 ++++++- .../modules/mysql/templates/buttonmen.cnf.erb | 11 ++++ deploy/vagrant/modules/php/manifests/init.pp | 51 +++++++++---------- src/engine/BMInterfaceGame.php | 4 ++ test/src/engine/BMGameTest.php | 30 +++++------ test/src/engine/BMInterfaceGameTest.php | 6 ++- test/src/engine/BMInterfaceTest.php | 16 +++--- tools/api-client/python/replay_loop | 8 +-- tools/api-client/python/replay_single_game | 2 +- util/grunt/circleci-grunt.sh | 3 +- 23 files changed, 194 insertions(+), 101 deletions(-) create mode 100644 deploy/vagrant/modules/apt/templates/10periodic.erb create mode 100644 deploy/vagrant/modules/javascript/templates/install_phantomjs.erb create mode 100644 deploy/vagrant/modules/mysql/templates/buttonmen.cnf.erb diff --git a/.circleci/config.yml b/.circleci/config.yml index 1a86eec89..5851898b5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,22 +1,22 @@ version: 2 jobs: build: - machine: - image: circleci/classic:latest + docker: + - image: ubuntu:16.04 steps: - checkout - run: name: Symlink /buttonmen - command: sudo ln -s /home/circleci/project /buttonmen + command: ln -s /root/project /buttonmen - run: name: Make sure log dir exists command: mkdir -p build/logs - run: name: Bootstrap puppet - command: sudo bash deploy/vagrant/bootstrap.sh + command: bash deploy/vagrant/bootstrap.sh - run: name: Run puppet - command: sudo puppet apply --modulepath=/buttonmen/deploy/vagrant/modules /buttonmen/deploy/circleci/manifests/init.pp + command: puppet apply --modulepath=/buttonmen/deploy/vagrant/modules /buttonmen/deploy/circleci/manifests/init.pp - run: name: Audit line termination of all files in the tree to match Button Men standard command: python deploy/circleci/audit_newlines.py @@ -34,16 +34,20 @@ jobs: command: phpcs --report=checkstyle --report-file=./build/logs/checkstyle.xml --standard=./deploy/circleci/checkstyle/buttonmen.xml ./src/api ./src/engine - run: name: Run unit tests using PHPUnit and generates junit.xml and clover.xml - command: php /etc/php5/deploy-includes/phpunit.phar --bootstrap ./deploy/circleci/phpunit_bootstrap.php --log-junit build/logs/junit.xml --coverage-clover build/logs/clover.xml --debug test/ + command: phpunit --bootstrap ./deploy/circleci/phpunit_bootstrap.php --log-junit build/logs/junit.xml --coverage-clover build/logs/clover.xml --debug test/ - run: name: Install dummy API files created by PHPUnit into test webserver - command: sudo rsync -av src/api/dummy_data/ /var/www/api/dummy_data/ + command: rsync -av src/api/dummy_data/ /var/www/api/dummy_data/ - run: name: Verify dummy API files were fully installed command: bash ./deploy/circleci/verify_dummy_responder_files.sh src/api/dummy_data/ /var/www/api/dummy_data/ + - run: + name: unpack phantomjs + command: /bin/tar xjf /usr/local/src/phantomjs-1.9.7-linux-x86_64.tar.bz2 --strip-components=1 + working_directory: /usr/local - run: name: Run QUnit tests - command: /usr/bin/phantomjs --web-security=false /usr/local/etc/run-jscover-qunit.js http://localhost/test-ui/phantom-index.html + command: /usr/local/bin/phantomjs --web-security=false /usr/local/etc/run-jscover-qunit.js http://localhost/test-ui/phantom-index.html - run: name: Run python client unit tests command: /usr/bin/python ./test/tools/api-client/python/lib/test_bmapi.py @@ -54,19 +58,17 @@ jobs: command: pdepend --jdepend-xml=./build/logs/jdepend.xml --jdepend-chart=./build/pdepend/dependencies.svg --overview-pyramid=build/pdepend/overview-pyramid.svg ./src - run: name: Generate pmd.xml using PHPMD - command: php /etc/php5/deploy-includes/phpmd.phar ./src xml ./deploy/circleci/pmd/buttonmen.xml --reportfile ./build/logs/pmd.xml + command: php /etc/php/7.0/deploy-includes/phpmd.phar ./src xml ./deploy/circleci/pmd/buttonmen.xml --reportfile ./build/logs/pmd.xml - run: name: Generate phploc.csv - command: php /etc/php5/deploy-includes/phploc.phar --log-csv ./build/logs/phploc.csv ./src - - run: - name: Generate API documentation using PHPDocumentor - command: phpdoc -d ./src -i 'api/DummyApiResponder.php' -t ./build/api + command: php /etc/php/7.0/deploy-includes/phploc.phar --log-csv ./build/logs/phploc.csv ./src - run: name: Aggregate tool output with PHP_CodeBrowser - command: php /etc/php5/deploy-includes/phpcb.phar --log ./build/logs --source ./src --output ./build/code-browser + command: php /etc/php/7.0/deploy-includes/phpcb.phar --log ./build/logs --source ./src --output ./build/code-browser - store_artifacts: path: build # TODO: # * get phpcpd working again # * get javascript code coverage testing working again using jscover or equivalent +# * get phpdoc working again diff --git a/deploy/circleci/manifests/init.pp b/deploy/circleci/manifests/init.pp index f249273f1..4e85630ed 100644 --- a/deploy/circleci/manifests/init.pp +++ b/deploy/circleci/manifests/init.pp @@ -13,8 +13,6 @@ include "apt::client" include "ntp::client" include "postfix::base" - include "user::buttonmen-devs" - include "sudo::buttonmen-devs" # Node configuration needed for the circleci buttonmen server include "apache::server::circleci" diff --git a/deploy/vagrant/Vagrantfile b/deploy/vagrant/Vagrantfile index 7edf4401a..512c9d036 100644 --- a/deploy/vagrant/Vagrantfile +++ b/deploy/vagrant/Vagrantfile @@ -10,17 +10,17 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # please see the online documentation at vagrantup.com. # Every Vagrant virtual environment requires a box to build off of. - config.vm.box = "precise32" + config.vm.box = "ubuntu/xenial32" # The url from where the 'config.vm.box' box will be fetched if it # doesn't already exist on the user's system. - config.vm.box_url = "http://files.vagrantup.com/precise32.box" + #config.vm.box_url = "http://files.vagrantup.com/xenial32.box" # Create a forwarded port mapping which allows access to a specific port # within the machine from a port on the host machine. In the example below, # accessing "localhost:8080" will access port 80 on the guest machine. config.vm.network :forwarded_port, guest: 80, host: 8080 - config.vm.hostname = "sandbox.buttonweavers.com" + #config.vm.hostname = "sandbox.buttonweavers.com" # Create a private network, which allows host-only access to the machine # using a specific IP. @@ -64,9 +64,8 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # firewall settings aws.security_groups = ["buttonmen-dev"] - #aws.ami = "ami-7747d01e" aws.instance_type = "t1.micro" - aws.ami = "ami-a53264cc" + aws.ami = "ami-0735ea082a1534cac" override.ssh.username = "ubuntu" override.ssh.private_key_path = "BUTTONMEN_SSH_PRIVATE_KEY_PATH" diff --git a/deploy/vagrant/manifests/init.pp b/deploy/vagrant/manifests/init.pp index f09bf6c6d..dda2a6c5c 100644 --- a/deploy/vagrant/manifests/init.pp +++ b/deploy/vagrant/manifests/init.pp @@ -30,7 +30,7 @@ $puppet_timestamp = generate('/bin/date', '+%s') case "$operatingsystemrelease" { - "14.04": { + "14.04", "16.04": { $puppet_apache_sitesdir = "sites-enabled" } default: { @@ -46,7 +46,7 @@ include "sudo::buttonmen-devs" # Node configuration needed for the buttonmen server - include "apache::server" + include "apache::server::vagrant" include "php::base" include "mysql::server" include "buttonmen::server" diff --git a/deploy/vagrant/modules/apache/manifests/init.pp b/deploy/vagrant/modules/apache/manifests/init.pp index ac4ceb03b..2b704f895 100644 --- a/deploy/vagrant/modules/apache/manifests/init.pp +++ b/deploy/vagrant/modules/apache/manifests/init.pp @@ -14,30 +14,34 @@ require => Package["apache2"]; } - # Customize apache default site - file { - "/etc/apache2/sites-available/default": - ensure => file, - content => template("apache/site_default.erb"), - notify => Service["apache2"]; - } - # Monitor the error log include "apache::server::feature::monitor-logs" } -class apache::server::circleci { +class apache::server::vagrant { # include the base class include "apache::server" - # Disable the default site, so the buttonmen site will load file { + # Customize apache default site + "/etc/apache2/sites-available/000-default.conf": + ensure => file, + content => template("apache/site_default.erb"), + notify => Service["apache2"]; + + # Enable the default site under the default name "/etc/apache2/sites-enabled/000-default.conf": - ensure => absent, + ensure => link, + target => "/etc/apache2/sites-available/000-default.conf", notify => Service["apache2"]; } } +class apache::server::circleci { + # same configuration as vagrant + include "apache::server::vagrant" +} + class apache::server::feature::monitor-logs { # Install the logtail package diff --git a/deploy/vagrant/modules/apache/templates/site_default.erb b/deploy/vagrant/modules/apache/templates/site_default.erb index 013095ca7..46ca7c33c 100644 --- a/deploy/vagrant/modules/apache/templates/site_default.erb +++ b/deploy/vagrant/modules/apache/templates/site_default.erb @@ -2,6 +2,26 @@ ServerAdmin webmaster@localhost DocumentRoot /var/www + + # Multiviews is what we use to redirect e.g. responder to responder.php + MultiviewsMatch Any + + ## Set environment variables for buttonmen database access + + # Database 1 (primary) + SetEnv DB1_HOST 127.0.0.1 + SetEnv DB1_PORT 3306 + SetEnv DB1_NAME buttonmen + SetEnv DB1_USER bmuser1 + SetEnv DB1_PASS 79eWZGs2RohkIZMVElU6 + + # Database 2 (test) + SetEnv DB2_HOST 127.0.0.1 + SetEnv DB2_PORT 3306 + SetEnv DB2_NAME buttonmen_test + SetEnv DB2_USER bmtest + SetEnv DB2_PASS bmtestpass + Options FollowSymLinks AllowOverride None diff --git a/deploy/vagrant/modules/apt/manifests/init.pp b/deploy/vagrant/modules/apt/manifests/init.pp index 8ef525745..917774bde 100644 --- a/deploy/vagrant/modules/apt/manifests/init.pp +++ b/deploy/vagrant/modules/apt/manifests/init.pp @@ -3,4 +3,18 @@ "apt_client_update": command => "/usr/bin/apt-get update"; } + + # Make sure generic base packages are installed, for the benefit + # of minimal environments like CircleCI docker + package { + "rsync": ensure => installed; + "wget": ensure => installed; + } + + # Configure periodic apt cron job + file { + "/etc/apt/apt.conf.d/10periodic": + ensure => file, + content => template("apt/10periodic.erb"); + } } diff --git a/deploy/vagrant/modules/apt/templates/10periodic.erb b/deploy/vagrant/modules/apt/templates/10periodic.erb new file mode 100644 index 000000000..df9327c24 --- /dev/null +++ b/deploy/vagrant/modules/apt/templates/10periodic.erb @@ -0,0 +1,9 @@ +##### /etc/apt/apt.conf.d/10periodic + +# Default xenial settings +APT::Periodic::Update-Package-Lists "1"; +APT::Periodic::Download-Upgradeable-Packages "0"; +APT::Periodic::AutocleanInterval "0"; + +# Do not automatically perform package updates +APT::Periodic::Unattended-Upgrade "0"; diff --git a/deploy/vagrant/modules/buttonmen/manifests/init.pp b/deploy/vagrant/modules/buttonmen/manifests/init.pp index 46306dfd1..e67c5e537 100644 --- a/deploy/vagrant/modules/buttonmen/manifests/init.pp +++ b/deploy/vagrant/modules/buttonmen/manifests/init.pp @@ -55,7 +55,7 @@ exec { "buttonmen_src_rsync": command => "/usr/bin/rsync -a --delete /buttonmen/src/ /var/www/", - require => Package["apache2"]; + require => [ Package["rsync"], Package["apache2"] ]; "buttonmen_uitest_rsync": command => "/usr/bin/rsync -a --delete /buttonmen/test/src/ui/ /var/www/test-ui/", @@ -63,7 +63,7 @@ "buttonmen_create_databases": command => "/usr/local/bin/create_buttonmen_databases", - require => [ Package["mysql-server"], + require => [ Service["mysql"], Exec["buttonmen_src_rsync"] ]; diff --git a/deploy/vagrant/modules/buttonmen/templates/phpunit.php.erb b/deploy/vagrant/modules/buttonmen/templates/phpunit.php.erb index 9019dba9a..fa2ef65e1 100644 --- a/deploy/vagrant/modules/buttonmen/templates/phpunit.php.erb +++ b/deploy/vagrant/modules/buttonmen/templates/phpunit.php.erb @@ -6,7 +6,7 @@ // Include /etc/php5/deploy-includes for phpunit itself. // Include /buttonmen/src for now, so the individual unit tests can find the base classes -set_include_path( "/etc/php5/deploy-includes:/buttonmen/src:" . ini_get( "include_path" ) ); +set_include_path( "/etc/php/7.0/deploy-includes:/buttonmen/src:" . ini_get( "include_path" ) ); $BM_RAND_VALS = array(); $BM_SKILL_RAND_VALS = array(); diff --git a/deploy/vagrant/modules/buttonmen/templates/run_buttonmen_tests.erb b/deploy/vagrant/modules/buttonmen/templates/run_buttonmen_tests.erb index f8697a56d..c040fc614 100644 --- a/deploy/vagrant/modules/buttonmen/templates/run_buttonmen_tests.erb +++ b/deploy/vagrant/modules/buttonmen/templates/run_buttonmen_tests.erb @@ -30,7 +30,7 @@ echo "------------------------------------------------------------------------" # Run PHP unit tests echo "Running PHP unit tests" cd /buttonmen/src -php /etc/php5/deploy-includes/phpunit.phar --bootstrap /usr/local/etc/buttonmen_phpunit.php /buttonmen/test +phpunit --bootstrap /usr/local/etc/buttonmen_phpunit.php /buttonmen/test if [ "$?" = "0" ]; then echo "Passed" else diff --git a/deploy/vagrant/modules/javascript/manifests/init.pp b/deploy/vagrant/modules/javascript/manifests/init.pp index a8a95de29..eac287b1d 100644 --- a/deploy/vagrant/modules/javascript/manifests/init.pp +++ b/deploy/vagrant/modules/javascript/manifests/init.pp @@ -1,7 +1,10 @@ class javascript::type::circleci { package { + "npm": ensure => installed; + "nodejs-legacy": ensure => installed; + + # we'll downgrade phantomjs later, but install it via apt to get its dependencies "phantomjs": ensure => installed; - "jscoverage": ensure => installed; } file { @@ -9,4 +12,10 @@ ensure => file, content => template("javascript/run-jscover-qunit.js.erb"); } + + exec { + "javascript_wget_phantomjs": + command => "/usr/bin/wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.7-linux-x86_64.tar.bz2 -O /usr/local/src/phantomjs-1.9.7-linux-x86_64.tar.bz2", + creates => "/usr/local/src/phantomjs-1.9.7-linux-x86_64.tar.bz2"; + } } diff --git a/deploy/vagrant/modules/javascript/templates/install_phantomjs.erb b/deploy/vagrant/modules/javascript/templates/install_phantomjs.erb new file mode 100644 index 000000000..d940535ef --- /dev/null +++ b/deploy/vagrant/modules/javascript/templates/install_phantomjs.erb @@ -0,0 +1,13 @@ +#!/bin/bash +##### Install phantomjs + +set -e +set -x + +PHANTOMJS_VERSION_NAME="phantomjs-1.9.7-linux-x86_64" + +cd /tmp +/usr/bin/wget https://bitbucket.org/ariya/phantomjs/downloads/${PHANTOMJS_VERSION_NAME}.tar.bz2 -O /tmp/${PHANTOMJS_VERSION_NAME}.tar.bz2 +sleep 10 +/bin/tar xjf ${PHANTOMJS_VERSION_NAME}.tar.bz2 +cp ${PHANTOMJS_VERSION_NAME}/bin/phantomjs /usr/local/bin/phantomjs diff --git a/deploy/vagrant/modules/mysql/manifests/init.pp b/deploy/vagrant/modules/mysql/manifests/init.pp index 442b19864..480ca383e 100644 --- a/deploy/vagrant/modules/mysql/manifests/init.pp +++ b/deploy/vagrant/modules/mysql/manifests/init.pp @@ -4,9 +4,25 @@ package { # Install mysql-server and php5-mysql packages "mysql-server": ensure => installed; - "php5-mysql": ensure => installed; + "php-mysql": ensure => installed; # Install python-mysqldb for use by helper scripts "python-mysqldb": ensure => installed; } + + # Run mysqld + service { + "mysql": + ensure => running, + enable => true, + require => Package["mysql-server"]; + } + + # Customize mysqld for buttonmen use + file { + "/etc/mysql/mysql.conf.d/buttonmen.cnf": + ensure => file, + content => template("mysql/buttonmen.cnf.erb"), + notify => Service["mysql"]; + } } diff --git a/deploy/vagrant/modules/mysql/templates/buttonmen.cnf.erb b/deploy/vagrant/modules/mysql/templates/buttonmen.cnf.erb new file mode 100644 index 000000000..166b20e93 --- /dev/null +++ b/deploy/vagrant/modules/mysql/templates/buttonmen.cnf.erb @@ -0,0 +1,11 @@ +# mysql configuration for buttonmen servers + +[mysqld] + +# Ubuntu 16.04 default sql_mode is: +# ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION +# We need to remove: +# * NO_ZERO_DATE - errors out on default 0 timestamps +# * STRICT_TRANS_TABLES - yields errors like: Field 'X' doesn't have a default value +# * ONLY_FULL_GROUP_BY - a search in BMInterface::search_game_history violates this +sql_mode=NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION diff --git a/deploy/vagrant/modules/php/manifests/init.pp b/deploy/vagrant/modules/php/manifests/init.pp index d62844286..525026a01 100644 --- a/deploy/vagrant/modules/php/manifests/init.pp +++ b/deploy/vagrant/modules/php/manifests/init.pp @@ -1,33 +1,30 @@ class php::base { - # Make sure php5 and libapache2-mod-php5 are installed + # Make sure php7 and libapache2-mod-php are installed package { - "php5": ensure => installed; - "libapache2-mod-php5": ensure => installed; + "php": ensure => installed; + "libapache2-mod-php": ensure => installed; + "php7.0-mbstring": ensure => installed; } file { - "/etc/php5/apache2/conf.d/buttonmen.ini": + "/etc/php/7.0/apache2/conf.d/buttonmen.ini": ensure => file, content => template("php/buttonmen.ini.erb"), notify => Service["apache2"], - require => Package["libapache2-mod-php5"]; + require => Package["libapache2-mod-php"]; - "/etc/php5/deploy-includes": + "/etc/php/7.0/deploy-includes": ensure => directory, - require => Package["libapache2-mod-php5"]; + require => Package["libapache2-mod-php"]; } include "php::base::feature::phpunit" } class php::base::feature::phpunit { - exec { - # TODO: once we upgrade PHP, start getting the latest version of phpunit again - "php_wget_phpunit": - command => "/usr/bin/wget --no-verbose -O /etc/php5/deploy-includes/phpunit.phar http://www.glassonion.org/misc/phpunit-4.8.36.phar", - creates => "/etc/php5/deploy-includes/phpunit.phar", - require => File["/etc/php5/deploy-includes"]; + package { + "phpunit": ensure => installed; } } @@ -37,8 +34,8 @@ package { "php-pear": ensure => installed; - "php5-xdebug": ensure => installed; - "php5-xsl": ensure => installed; + "php-xdebug": ensure => installed; + "php-xsl": ensure => installed; } exec { @@ -52,24 +49,24 @@ creates => "/usr/bin/pdepend"; "php_wget_install_phpmd": - command => "/usr/bin/wget --no-verbose -O /etc/php5/deploy-includes/phpmd.phar http://static.phpmd.org/php/latest/phpmd.phar", - creates => "/etc/php5/deploy-includes/phpmd.phar", - require => File["/etc/php5/deploy-includes"]; + command => "/usr/bin/wget --no-verbose -O /etc/php/7.0/deploy-includes/phpmd.phar http://static.phpmd.org/php/latest/phpmd.phar", + creates => "/etc/php/7.0/deploy-includes/phpmd.phar", + require => File["/etc/php/7.0/deploy-includes"]; "php_wget_install_phpcpd": - command => "/usr/bin/wget --no-verbose -O /etc/php5/deploy-includes/phpcpd.phar https://phar.phpunit.de/phpcpd.phar", - creates => "/etc/php5/deploy-includes/phpcpd.phar", - require => File["/etc/php5/deploy-includes"]; + command => "/usr/bin/wget --no-verbose -O /etc/php/7.0/deploy-includes/phpcpd.phar https://phar.phpunit.de/phpcpd.phar", + creates => "/etc/php/7.0/deploy-includes/phpcpd.phar", + require => File["/etc/php/7.0/deploy-includes"]; "php_wget_install_phploc": - command => "/usr/bin/wget --no-verbose -O /etc/php5/deploy-includes/phploc.phar https://phar.phpunit.de/phploc.phar", - creates => "/etc/php5/deploy-includes/phploc.phar", - require => File["/etc/php5/deploy-includes"]; + command => "/usr/bin/wget --no-verbose -O /etc/php/7.0/deploy-includes/phploc.phar https://phar.phpunit.de/phploc.phar", + creates => "/etc/php/7.0/deploy-includes/phploc.phar", + require => File["/etc/php/7.0/deploy-includes"]; "php_wget_install_phpcb": - command => "/usr/bin/wget --no-verbose -O /etc/php5/deploy-includes/phpcb.phar https://github.com/bytepark/php-phar-qatools/blob/master/phpcb.phar", - creates => "/etc/php5/deploy-includes/phpcb.phar", - require => File["/etc/php5/deploy-includes"]; + command => "/usr/bin/wget --no-verbose -O /etc/php/7.0/deploy-includes/phpcb.phar https://github.com/bytepark/php-phar-qatools/blob/master/phpcb.phar", + creates => "/etc/php/7.0/deploy-includes/phpcb.phar", + require => File["/etc/php/7.0/deploy-includes"]; "php_pear_discover_phpdoc": command => "/usr/bin/pear channel-discover pear.phpdoc.org", diff --git a/src/engine/BMInterfaceGame.php b/src/engine/BMInterfaceGame.php index 340c32bb0..f50ad38e0 100644 --- a/src/engine/BMInterfaceGame.php +++ b/src/engine/BMInterfaceGame.php @@ -1035,6 +1035,10 @@ public function react_to_auxiliary( ) { try { $game = $this->load_game($gameId); + if (!$game) { + $this->set_message('Invalid game'); + return FALSE; + } if (!$this->is_action_current( $game, BMGameState::CHOOSE_AUXILIARY_DICE, diff --git a/test/src/engine/BMGameTest.php b/test/src/engine/BMGameTest.php index 3084dfeef..2c049f0b9 100644 --- a/test/src/engine/BMGameTest.php +++ b/test/src/engine/BMGameTest.php @@ -2551,7 +2551,7 @@ public function test__set_active_die_array_array() { try { $this->object->activeDieArrayArray = 'abc'; $this->fail('Active die array array must be an array.'); - } catch (PHPUnit_Framework_Error $expected) { + } catch (TypeError $expected) { } try { @@ -2729,7 +2729,7 @@ public function test__set_captured_die_array_array() { try { $this->object->capturedDieArrayArray = 'abc'; $this->fail('Captured die array array must be an array.'); - } catch (PHPUnit_Framework_Error $expected) { + } catch (TypeError $expected) { } try { @@ -5874,7 +5874,7 @@ public function test_berserk_round() { $this->assertEquals('V', $game->activeDieArrayArray[1][2]->swingType); $this->assertEquals(11, $game->activeDieArrayArray[1][2]->swingValue); $this->assertEquals(6, $game->activeDieArrayArray[1][2]->max); - $this->assertTrue(isset($game->activeDieArrayArray[1][2]->value)); + $this->assertNotNull($game->activeDieArrayArray[1][2]->value); $this->assertEquals(array(40.5, -12.0), $game->roundScoreArray); } @@ -9024,9 +9024,9 @@ public function test_option_game() { $game->activeDieArrayArray[0][2]->set_optionValue(12); $game->activeDieArrayArray[0][3]->set_optionValue(16); $game->activeDieArrayArray[0][4]->set_optionValue(20); - $this->assertTrue(isset($game->activeDieArrayArray[0][2]->max)); - $this->assertTrue(isset($game->activeDieArrayArray[0][3]->max)); - $this->assertTrue(isset($game->activeDieArrayArray[0][4]->max)); + $this->assertNotNull($game->activeDieArrayArray[0][2]->max); + $this->assertNotNull($game->activeDieArrayArray[0][3]->max); + $this->assertNotNull($game->activeDieArrayArray[0][4]->max); $this->assertEquals(12, $game->activeDieArrayArray[0][2]->max); $this->assertEquals(16, $game->activeDieArrayArray[0][3]->max); $this->assertEquals(20, $game->activeDieArrayArray[0][4]->max); @@ -9081,9 +9081,9 @@ public function test_option_game() { $game->activeDieArrayArray[1][2]->set_optionValue(8); $game->activeDieArrayArray[1][3]->set_optionValue(6); $game->activeDieArrayArray[1][4]->set_optionValue(12); - $this->assertTrue(isset($game->activeDieArrayArray[1][2]->max)); - $this->assertTrue(isset($game->activeDieArrayArray[1][3]->max)); - $this->assertTrue(isset($game->activeDieArrayArray[1][4]->max)); + $this->assertNotNull($game->activeDieArrayArray[1][2]->max); + $this->assertNotNull($game->activeDieArrayArray[1][3]->max); + $this->assertNotNull($game->activeDieArrayArray[1][4]->max); $this->assertEquals(8, $game->activeDieArrayArray[1][2]->max); $this->assertEquals(6, $game->activeDieArrayArray[1][3]->max); $this->assertEquals(12, $game->activeDieArrayArray[1][4]->max); @@ -9981,9 +9981,7 @@ public function test_default_round() { 'Default'); // attackType $game->proceed_to_next_user_action(); - // james: note that end normally shifts the pointer, so use - // call_user_func and array_values to avoid changing the original array - $lastLogEntry = call_user_func('end', array_values($game->actionLog)); + $lastLogEntry = $game->actionLog[count($game->actionLog) - 1]; $this->assertEquals('attack', $lastLogEntry->actionType); $this->assertEquals('Berserk', $lastLogEntry->params['attackType']); $this->assertEquals(1, $game->activeDieArrayArray[0][4]->max); @@ -10005,9 +10003,7 @@ public function test_default_round() { 'Default'); // attackType $game->proceed_to_next_user_action(); - // james: note that end normally shifts the pointer, so use - // call_user_func and array_values to avoid changing the original array - $lastLogEntry = call_user_func('end', array_values($game->actionLog)); + $lastLogEntry = $game->actionLog[count($game->actionLog) - 1]; $this->assertEquals('attack', $lastLogEntry->actionType); $this->assertEquals('Power', $lastLogEntry->params['attackType']); @@ -10027,9 +10023,7 @@ public function test_default_round() { 'Default'); // attackType $game->proceed_to_next_user_action(); - // james: note that end normally shifts the pointer, so use - // call_user_func and array_values to avoid changing the original array - $lastLogEntry = call_user_func('end', array_values($game->actionLog)); + $lastLogEntry = $game->actionLog[count($game->actionLog) - 1]; $this->assertEquals('attack', $lastLogEntry->actionType); $this->assertEquals('Skill', $lastLogEntry->params['attackType']); diff --git a/test/src/engine/BMInterfaceGameTest.php b/test/src/engine/BMInterfaceGameTest.php index ef0be1085..d002bf3ef 100644 --- a/test/src/engine/BMInterfaceGameTest.php +++ b/test/src/engine/BMInterfaceGameTest.php @@ -434,9 +434,11 @@ public function test_create_game_with_two_random_buttons() { $gameId = $retval['gameId']; $game = self::load_game($gameId); - $this->assertFalse(empty($game->buttonArray[0]->name)); + $this->assertNotNull($game->buttonArray[0]->name); + $this->assertTrue(is_string($game->buttonArray[0]->name)); $this->assertNotEquals('__random', $game->buttonArray[0]->name); - $this->assertFalse(empty($game->buttonArray[1]->name)); + $this->assertNotNull($game->buttonArray[1]->name); + $this->assertTrue(is_string($game->buttonArray[1]->name)); $this->assertNotEquals('__random', $game->buttonArray[1]->name); $this->assertGreaterThan(BMGameState::START_GAME, $game->gameState); } diff --git a/test/src/engine/BMInterfaceTest.php b/test/src/engine/BMInterfaceTest.php index c202f9977..ccd307982 100644 --- a/test/src/engine/BMInterfaceTest.php +++ b/test/src/engine/BMInterfaceTest.php @@ -409,8 +409,8 @@ public function test_swing_value_reset_at_end_of_round() { $this->assertEquals(array('X'), array_keys($game->swingValueArrayArray[0])); $this->assertFalse(isset($game->swingValueArrayArray[0]['X'])); $this->assertEquals(array('V'), array_keys($game->swingValueArrayArray[1])); - $this->assertTrue(isset($game->swingValueArrayArray[1]['V'])); - $this->assertTrue(isset($game->activeDieArrayArray[1][4]->swingValue)); + $this->assertNotNull($game->swingValueArrayArray[1]['V']); + $this->assertNotNull($game->activeDieArrayArray[1][4]->swingValue); $this->assertEquals(array(TRUE, FALSE), $game->waitingOnActionArray); $this->assertEquals(array(array('X' => NULL), array('V' => 11)), @@ -1413,9 +1413,9 @@ public function test_option_game() { $this->assertEquals(array(array(2 => 12, 3 => 16, 4 => 20), array()), $game->optValueArrayArray); - $this->assertTrue(isset($game->activeDieArrayArray[0][2]->max)); - $this->assertTrue(isset($game->activeDieArrayArray[0][3]->max)); - $this->assertTrue(isset($game->activeDieArrayArray[0][4]->max)); + $this->assertNotNull($game->activeDieArrayArray[0][2]->max); + $this->assertNotNull($game->activeDieArrayArray[0][3]->max); + $this->assertNotNull($game->activeDieArrayArray[0][4]->max); $this->assertEquals(12, $game->activeDieArrayArray[0][2]->max); $this->assertEquals(16, $game->activeDieArrayArray[0][3]->max); $this->assertEquals(20, $game->activeDieArrayArray[0][4]->max); @@ -1486,9 +1486,9 @@ public function test_option_game() { array(2 => 8, 3 => 6, 4 => 12)), $game->optValueArrayArray); - $this->assertTrue(isset($game->activeDieArrayArray[1][2]->max)); - $this->assertTrue(isset($game->activeDieArrayArray[1][3]->max)); - $this->assertTrue(isset($game->activeDieArrayArray[1][4]->max)); + $this->assertNotNull($game->activeDieArrayArray[1][2]->max); + $this->assertNotNull($game->activeDieArrayArray[1][3]->max); + $this->assertNotNull($game->activeDieArrayArray[1][4]->max); $this->assertEquals(8, $game->activeDieArrayArray[1][2]->max); $this->assertEquals(6, $game->activeDieArrayArray[1][3]->max); $this->assertEquals(12, $game->activeDieArrayArray[1][4]->max); diff --git a/tools/api-client/python/replay_loop b/tools/api-client/python/replay_loop index 04c45856e..c6f747dc8 100755 --- a/tools/api-client/python/replay_loop +++ b/tools/api-client/python/replay_loop @@ -122,7 +122,7 @@ def test_file(filename): # actually run the test, capturing output logfile = '%s/%s.output' % (STATEDIR, filename) - cmdargs = 'sudo -u %s sh -c "php /etc/php5/deploy-includes/phpunit.phar --bootstrap /usr/local/etc/buttonmen_phpunit.php --group fulltest_deps /buttonmen/test/src/api/ 2>&1" | tee %s' % (USERNAME, logfile) + cmdargs = 'sudo -u %s sh -c "phpunit --bootstrap /usr/local/etc/buttonmen_phpunit.php --group fulltest_deps /buttonmen/test/src/api/ 2>&1" | tee %s' % (USERNAME, logfile) print "About to execute: %s" % cmdargs os.system(cmdargs) return @@ -136,9 +136,9 @@ def test_new_games(): # received. # Reset primary and test databases - os.system('echo "drop database buttonmen" | mysql -u root') - os.system('/usr/local/bin/create_buttonmen_databases') - os.system('cat ~/example_players.sql | mysql -u root') + os.system('echo "drop database buttonmen" | sudo mysql') + os.system('sudo /usr/local/bin/create_buttonmen_databases') + os.system('cat ~/example_players.sql | sudo mysql') os.chdir(HOMEBMDIR) retval = os.system('./test_log_games 100') diff --git a/tools/api-client/python/replay_single_game b/tools/api-client/python/replay_single_game index 94efbbd1d..f08425254 100755 --- a/tools/api-client/python/replay_single_game +++ b/tools/api-client/python/replay_single_game @@ -73,7 +73,7 @@ def test_game(filename, gamenum): os.chdir(SRCDIR) # actually run the test (with output to stdout/stderr) - cmdargs = 'sudo -u %s sh -c "php /etc/php5/deploy-includes/phpunit.phar --bootstrap /usr/local/etc/buttonmen_phpunit.php --group fulltest_deps /buttonmen/test/src/api/ 2>&1"' % (USERNAME) + cmdargs = 'sudo -u %s sh -c "phpunit --bootstrap /usr/local/etc/buttonmen_phpunit.php --group fulltest_deps /buttonmen/test/src/api/ 2>&1"' % (USERNAME) print "About to execute: %s" % cmdargs os.system(cmdargs) return diff --git a/util/grunt/circleci-grunt.sh b/util/grunt/circleci-grunt.sh index 8481af161..f0693cace 100644 --- a/util/grunt/circleci-grunt.sh +++ b/util/grunt/circleci-grunt.sh @@ -1,5 +1,6 @@ #!/bin/sh cd util/grunt +./npm_install_grunt npm install -grunt circleci --no-color +./node_modules/grunt-cli/bin/grunt circleci --no-color