| 
									
										
										
										
											2016-11-19 15:55:49 +01:00
										 |  |  | #!/bin/bash
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-19 16:13:57 +01:00
										 |  |  | DATABASE=./storage/database/database.sqlite | 
					
						
							|  |  |  | DATABASECOPY=./storage/database/databasecopy.sqlite | 
					
						
							|  |  |  | ORIGINALENV=./.env | 
					
						
							|  |  |  | BACKUPENV=./.env.current | 
					
						
							|  |  |  | TESTINGENV=./.env.testing | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-19 16:28:04 +01:00
										 |  |  | # do something with flags: | 
					
						
							| 
									
										
										
										
											2016-12-25 11:50:42 +01:00
										 |  |  | resetTestFlag='' | 
					
						
							| 
									
										
										
										
											2016-11-19 20:30:30 +01:00
										 |  |  | testflag='' | 
					
						
							|  |  |  | coverageflag='' | 
					
						
							| 
									
										
										
										
											2017-04-27 08:26:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-22 07:05:55 +02:00
										 |  |  | featureflag='' | 
					
						
							| 
									
										
										
										
											2017-03-04 06:54:05 +01:00
										 |  |  | featuretestclass='' | 
					
						
							| 
									
										
										
										
											2017-04-27 08:26:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | unitflag='' | 
					
						
							|  |  |  | unittestclass='' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-09 16:30:33 +01:00
										 |  |  | verbalflag='' | 
					
						
							| 
									
										
										
										
											2016-12-22 19:51:49 +01:00
										 |  |  | testsuite='' | 
					
						
							| 
									
										
										
										
											2017-04-22 07:05:55 +02:00
										 |  |  | configfile='phpunit.xml'; | 
					
						
							| 
									
										
										
										
											2016-11-19 16:28:04 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-27 08:26:58 +02:00
										 |  |  | while getopts 'vcrtf:u:s:' flag; do | 
					
						
							| 
									
										
										
										
											2016-11-19 16:28:04 +01:00
										 |  |  |   case "${flag}" in | 
					
						
							| 
									
										
										
										
											2016-11-20 08:30:25 +01:00
										 |  |  |     r) | 
					
						
							| 
									
										
										
										
											2016-12-25 11:50:42 +01:00
										 |  |  |         resetTestFlag='true' | 
					
						
							| 
									
										
										
										
											2016-11-20 08:30:25 +01:00
										 |  |  |     ;; | 
					
						
							|  |  |  |     t) | 
					
						
							|  |  |  |         testflag='true' | 
					
						
							|  |  |  |     ;; | 
					
						
							|  |  |  |     c) | 
					
						
							|  |  |  |         coverageflag='true' | 
					
						
							| 
									
										
										
										
											2017-04-22 07:05:55 +02:00
										 |  |  |         configfile='phpunit.coverage.xml'; | 
					
						
							| 
									
										
										
										
											2016-11-20 08:30:25 +01:00
										 |  |  |     ;; | 
					
						
							| 
									
										
										
										
											2016-12-09 16:30:33 +01:00
										 |  |  |     v) | 
					
						
							| 
									
										
										
										
											2016-12-22 19:51:49 +01:00
										 |  |  |         verbalflag=' -v --debug' | 
					
						
							|  |  |  |         echo "Will be verbal about it" | 
					
						
							| 
									
										
										
										
											2016-12-09 16:30:33 +01:00
										 |  |  |     ;; | 
					
						
							| 
									
										
										
										
											2017-03-04 06:54:05 +01:00
										 |  |  |     f) | 
					
						
							| 
									
										
										
										
											2017-04-22 07:05:55 +02:00
										 |  |  |         featureflag='true' | 
					
						
							| 
									
										
										
										
											2017-03-04 06:54:05 +01:00
										 |  |  |         featuretestclass=./tests/Feature/$OPTARG | 
					
						
							|  |  |  |         echo "Will only run Feature test $OPTARG" | 
					
						
							| 
									
										
										
										
											2016-11-20 08:30:25 +01:00
										 |  |  |     ;; | 
					
						
							| 
									
										
										
										
											2017-04-27 08:26:58 +02:00
										 |  |  |     u) | 
					
						
							|  |  |  |         unitflag='true' | 
					
						
							|  |  |  |         unittestclass=./tests/Unit/$OPTARG | 
					
						
							|  |  |  |         echo "Will only run Unit test $OPTARG" | 
					
						
							|  |  |  |     ;; | 
					
						
							| 
									
										
										
										
											2016-12-22 19:51:49 +01:00
										 |  |  |     s) | 
					
						
							|  |  |  |         testsuite="--testsuite $OPTARG" | 
					
						
							|  |  |  |         echo "Will only run test suite '$OPTARG'" | 
					
						
							|  |  |  |     ;; | 
					
						
							| 
									
										
										
										
											2016-11-19 16:28:04 +01:00
										 |  |  |     *) error "Unexpected option ${flag}" ;; | 
					
						
							|  |  |  |   esac | 
					
						
							|  |  |  | done | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-27 08:26:58 +02:00
										 |  |  | if [[ $coverageflag == "true" && ($featureflag == "true" || $unitflag == "true") ]] | 
					
						
							| 
									
										
										
										
											2017-04-22 07:05:55 +02:00
										 |  |  | then | 
					
						
							|  |  |  |     echo "Use config file specific.xml" | 
					
						
							|  |  |  |     configfile='phpunit.coverage.specific.xml' | 
					
						
							|  |  |  | fi | 
					
						
							| 
									
										
										
										
											2016-11-19 16:28:04 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-19 16:13:57 +01:00
										 |  |  | # backup current config (if it exists): | 
					
						
							|  |  |  | if [ -f $ORIGINALENV ]; then | 
					
						
							|  |  |  |     mv $ORIGINALENV $BACKUPENV | 
					
						
							|  |  |  | fi | 
					
						
							| 
									
										
										
										
											2016-11-19 15:55:49 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | # enable testing config | 
					
						
							| 
									
										
										
										
											2016-11-19 16:13:57 +01:00
										 |  |  | cp $TESTINGENV $ORIGINALENV | 
					
						
							| 
									
										
										
										
											2016-11-19 15:55:49 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-19 16:28:04 +01:00
										 |  |  | # reset database (optional) | 
					
						
							| 
									
										
										
										
											2016-12-25 11:50:42 +01:00
										 |  |  | if [[ $resetTestFlag == "true" ]] | 
					
						
							| 
									
										
										
										
											2016-11-19 16:13:57 +01:00
										 |  |  | then | 
					
						
							| 
									
										
										
										
											2016-11-19 15:55:49 +01:00
										 |  |  |     echo "Must reset database" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # touch files to make sure they exist. | 
					
						
							|  |  |  |     touch $DATABASE | 
					
						
							|  |  |  |     touch $DATABASECOPY | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # truncate original database file | 
					
						
							|  |  |  |     truncate $DATABASE --size 0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # run migration | 
					
						
							|  |  |  |     php artisan migrate:refresh --seed | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-25 11:50:42 +01:00
										 |  |  |     # call test data generation script | 
					
						
							| 
									
										
										
										
											2017-01-20 08:03:26 +01:00
										 |  |  |     $(which php) /sites/FF3/test-data/artisan generate:data local sqlite | 
					
						
							| 
									
										
										
										
											2017-06-07 07:38:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # also run upgrade routine: | 
					
						
							|  |  |  |     $(which php) /sites/FF3/firefly-iii/artisan firefly:upgrade-database | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-19 15:55:49 +01:00
										 |  |  |     # copy new database over backup (resets backup) | 
					
						
							|  |  |  |     cp $DATABASE $DATABASECOPY | 
					
						
							| 
									
										
										
										
											2017-06-28 15:27:31 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # copy new database to test-data repository: | 
					
						
							|  |  |  |     cp $DATABASE /sites/FF3/test-data/storage/database.sqlite | 
					
						
							| 
									
										
										
										
											2016-11-19 15:55:49 +01:00
										 |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-19 16:28:04 +01:00
										 |  |  | # do not reset database (optional) | 
					
						
							| 
									
										
										
										
											2016-12-25 11:50:42 +01:00
										 |  |  | if [[ $resetTestFlag == "" ]] | 
					
						
							| 
									
										
										
										
											2016-11-19 16:28:04 +01:00
										 |  |  | then | 
					
						
							|  |  |  |     echo "Will not reset database" | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-27 15:46:52 +01:00
										 |  |  | echo "Copy test database over original" | 
					
						
							| 
									
										
										
										
											2016-11-19 15:55:49 +01:00
										 |  |  | # take database from copy: | 
					
						
							|  |  |  | cp $DATABASECOPY $DATABASE | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-12 16:50:35 +01:00
										 |  |  | echo "clear caches and what-not.." | 
					
						
							|  |  |  | php artisan cache:clear | 
					
						
							|  |  |  | php artisan config:clear | 
					
						
							|  |  |  | php artisan route:clear | 
					
						
							| 
									
										
										
										
											2017-10-09 20:30:57 +02:00
										 |  |  | # php artisan twig:clean | 
					
						
							| 
									
										
										
										
											2017-02-12 16:50:35 +01:00
										 |  |  | php artisan view:clear | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-19 15:55:49 +01:00
										 |  |  | # run PHPUnit | 
					
						
							| 
									
										
										
										
											2016-11-19 20:30:30 +01:00
										 |  |  | if [[ $testflag == "" ]] | 
					
						
							| 
									
										
										
										
											2016-11-19 16:13:57 +01:00
										 |  |  | then | 
					
						
							| 
									
										
										
										
											2016-11-19 16:07:02 +01:00
										 |  |  |     echo "Must not run PHPUnit" | 
					
						
							|  |  |  | else | 
					
						
							| 
									
										
										
										
											2016-11-19 16:28:04 +01:00
										 |  |  |     echo "Must run PHPUnit" | 
					
						
							| 
									
										
										
										
											2016-11-19 20:30:30 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if [[ $coverageflag == "" ]] | 
					
						
							|  |  |  |     then | 
					
						
							| 
									
										
										
										
											2016-12-22 19:51:49 +01:00
										 |  |  |         echo "Must run PHPUnit without coverage:" | 
					
						
							| 
									
										
										
										
											2017-04-22 07:05:55 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-10 09:57:05 +01:00
										 |  |  |         echo "./vendor/bin/phpunit $verbalflag --configuration $configfile $featuretestclass $unittestclass $testsuite" | 
					
						
							|  |  |  |         ./vendor/bin/phpunit $verbalflag  --configuration $configfile $featuretestclass $unittestclass $testsuite | 
					
						
							| 
									
										
										
										
											2016-11-19 20:30:30 +01:00
										 |  |  |     else | 
					
						
							|  |  |  |         echo "Must run PHPUnit with coverage" | 
					
						
							| 
									
										
										
										
											2018-02-10 09:57:05 +01:00
										 |  |  |         echo "./vendor/bin/phpunit $verbalflag --configuration $configfile $featuretestclass $unittestclass $testsuite" | 
					
						
							|  |  |  |         ./vendor/bin/phpunit $verbalflag --configuration $configfile $featuretestclass $unittestclass $testsuite | 
					
						
							| 
									
										
										
										
											2016-11-19 20:30:30 +01:00
										 |  |  |     fi | 
					
						
							| 
									
										
										
										
											2016-11-19 16:07:02 +01:00
										 |  |  | fi | 
					
						
							| 
									
										
										
										
											2016-11-19 15:55:49 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | # restore current config: | 
					
						
							| 
									
										
										
										
											2016-11-19 16:13:57 +01:00
										 |  |  | if [ -f $BACKUPENV ]; then | 
					
						
							|  |  |  |     mv $BACKUPENV $ORIGINALENV | 
					
						
							| 
									
										
										
										
											2017-10-09 20:30:57 +02:00
										 |  |  | fi |