Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix running tests of framework #7

Closed
3 tasks
kamilwylegala opened this issue Dec 20, 2021 · 12 comments
Closed
3 tasks

Fix running tests of framework #7

kamilwylegala opened this issue Dec 20, 2021 · 12 comments

Comments

@kamilwylegala
Copy link
Owner

kamilwylegala commented Dec 20, 2021

Cake's test relay hevily on PHPUnit_Test_Case class which comes from old version of PHPUnit.

  • Check how many deprecation notices show up in logs.
  • Investigate effort to update PHPUnit and all tests
  • Check how much effort costs upgrading PHPUnit. Requred version of PHPUnit is 8. In previous versions of PHPUnit there is each() used which is removed in PHP 8.

Bootstrap file

Check if it helps to run tests of framework: cakephp/cakephp#12700 (comment)

@kamilwylegala kamilwylegala changed the title Check if unit tests are causing deprecation notices Check if unit tests work at all with PHPUnit 3.7 Dec 21, 2021
@kamilwylegala kamilwylegala changed the title Check if unit tests work at all with PHPUnit 3.7 Fix running tests of framework Dec 21, 2021
@ryantxr
Copy link

ryantxr commented Sep 26, 2022

I had to do this on my project. I decided to abandon the cake test blah approach in favor of using phpunit directly. I am not quite done, however, I could help to contribute some ideas, code and time if you're up to using that approach.

@kamilwylegala
Copy link
Owner Author

Hey @ryantxr

This is exactly what I do in my side project too 😊 I gave up on using cake test... and I'm just using plain and newest PHPUnit.

My initial idea of this issue is to be able to test framework itself with its tests. Currently here we're just patching Cake to meet PHP8 requirements but I rely on tests from my side project. No idea if tests are passing.

I already spend sometime on this problem but gave up after I saw how tangled tests are to "Cake's way" of testing.

Any idea how could we approach it with minimal effort?

@ryantxr
Copy link

ryantxr commented Sep 26, 2022

@kamilwylegala I don't know about minimal. There are two major challenges.

  1. Bootstrapping the cake environment via phpunit.xml. I have this working and I can share it with you.
  2. Loading fixtures. I have this working but I have not used it extensively yet.

I also autoload using composer. I think this is necessary to get it all working. This requires adding composer autoloader in app/Config/bootstrap.php. This also allows me to add new classes and load using use Some\Namespace\Class.

@mevdschee
Copy link

@ryantxr I'm interested in your progress, care to share?

NB: My fork is here: https://github.com/mevdschee/cakephp2-php8

@tenkoma
Copy link
Contributor

tenkoma commented Jan 8, 2023

@kamilwylegala

Hi!

I forked this repository to private and tried to see if I could run the test with GitHub Actions.
I was able to get the test to pass.

I also prepared a commit in the public repository.
Here is the branch and the results of the test run:

I want to create a pull request, but how do I create it?
Since the commits are arranged in the following procedure groups, should I separate them in each, or can I just put them together and make one pull request?

  1. First I could run the tests to the end anyway.
  2. Updated tests that failed due to the PHPUnit upgrade.
  3. Made changes that only required modifying the test code.
  4. Made a change that required a change in non-test code, but the reason for the change was easy to understand.
  5. Other failing tests were skipped by writing comments (I think it would be better to separate pull requests for this one)

@kamilwylegala
Copy link
Owner Author

Hey @tenkoma

I briefly checked the code. Great job! 😊

I also created merge request: https://github.com/kamilwylegala/cakephp2-php8/pull/23/files . I will review your code this week.

It includes all commits that you created in test branch and I think we could keep'em that way, i.e. no squashing, no grouping. You did awesome job by making detailed commit messages, I really like it. So maybe let's keep git history? What do you think?

@tenkoma
Copy link
Contributor

tenkoma commented Jan 9, 2023

@kamilwylegala

Yes, I would like to have the git history kept.
Thank you for making the merge request.

@tenkoma
Copy link
Contributor

tenkoma commented Jan 9, 2023

I used Docker Compose on my work PC to create a working environment, so I will share the configuration files.
This will allow to run some tests at hand.:smile:

Added: 2023/02/05 PostgreSQL/SQLite added

  1. Save the four files under a working copy of this repo.
  • docker-compose.yml,docker/web/Dockerfile,docker/mysql/1_initialize_database.sql and docker/pgsql/1_initialize_database.sql
  1. Copy .github/workflows/configs/database.php to app/Config/database.php and modify the following.
    • change $identities['mysql']['host'] to 'mysql'
    • change $identities['pgsql']['host'] to 'pgsql'
    • If you want to connect to PostgreSQL or SQLite for testing, change the first line of the DATABASE_CONFIG constructor to $db = 'pgsql'; or $db = 'sqlite';.
  2. Execute the following command in a shell.
docker compose up -d
docker compose exec web composer install
docker compose exec web ./vendors/bin/phpunit --stderr --verbose lib/Cake/Test/Case/AllTestsTest.php
contents of docker-compose.yml, docker/web/Dockerfile, docker/mysql/1_initialize_database.sql, docker/pgsql/1_initialize_database.sql

PROJECT_ROOT/docker-compose.yml

services:  
  web:  
    build: ./docker/web  
    environment:  
      PHP_IDE_CONFIG: "serverName=localhost"  
    volumes:  
      - ./:/var/www/html:cached  
    working_dir: /var/www/html  
    ports:  
      - "8000:80"  
    depends_on:  
      - mysql  
      - pgsql  
      - memcached  
      - redis  
  mysql:  
    image: mysql:5.6  
    platform: linux/amd64  
    command: mysqld --character-set-server=utf8 --collation-server=utf8_general_ci  
    environment:  
      MYSQL_ROOT_PASSWORD: root  
      MYSQL_DATABASE: cakephp_test  
      MYSQL_USER: cakephp_test  
      MYSQL_PASSWORD: secret  
    volumes:  
      - ./docker/mysql:/docker-entrypoint-initdb.d:cached  
      - mysql-data:/var/lib/mysql  
    ports:  
      - "3306:3306"  
  pgsql:  
    image: postgres:9.4  
    platform: linux/amd64  
    environment:  
      POSTGRES_DB: cakephp_test  
      POSTGRES_USER: postgres  
      POSTGRES_PASSWORD: postgres  
    volumes:  
      - ./docker/pgsql:/docker-entrypoint-initdb.d:cached  
      - pgsql-data:/var/lib/postgresql/data  
    ports:  
      - "5432:5432"  
  memcached:  
    image: memcached:latest  
    hostname: memcached  
    ports:  
      - "11211:11211"  
  redis:  
    image: "redis:latest"  
    hostname: redis  
    ports:  
      - "6379:6379"  
volumes:  
  mysql-data:  
  pgsql-data:

PROJECT_ROOT/docker/web/Dockerfile

FROM php:8.0-apache  
  
RUN apt-get update && apt-get install -y --no-install-recommends \  
    && apt-get install -y libpq-dev libzip-dev unzip openssl libmcrypt-dev libmemcached-dev locales \  
    && rm -rf /var/lib/apt/lists/*  
  
RUN docker-php-ext-install pdo_mysql pdo_pgsql zip \  
    && pecl install apcu redis memcached mcrypt xdebug \  
    && docker-php-ext-enable redis memcached mcrypt \  
    && docker-php-ext-enable xdebug \  
    && echo "extension=apcu.so" >> /usr/local/etc/php/php.ini \  
    && echo "apc.enable_cli = 1" >> /usr/local/etc/php/php.ini  
  
COPY --from=composer /usr/bin/composer /usr/local/bin/composer  
  
RUN sed -i '/de_DE /s/^# //g' /etc/locale.gen \  
    && sed -i '/es_ES /s/^# //g' /etc/locale.gen \  
    && locale-gen  
  
ENV APACHE_DOCUMENT_ROOT /var/www/html/app/webroot  
  
RUN a2enmod rewrite  
  
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf  
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf

PROJECT_ROOT/docker/mysql/1_initialize_database.sql

CREATE DATABASE IF NOT EXISTS cakephp_test ;
GRANT ALL ON cakephp_test.* TO 'cakephp_test'@'%' ;
CREATE DATABASE IF NOT EXISTS cakephp_test2 ;
GRANT ALL ON cakephp_test2.* TO 'cakephp_test'@'%' ;
CREATE DATABASE IF NOT EXISTS cakephp_test3 ;
GRANT ALL ON cakephp_test3.* TO 'cakephp_test'@'%' ;
FLUSH PRIVILEGES ;

PROJECT_ROOT/docker/pgsql/1_initialize_database.sql

\c cakephp_test  
  
CREATE SCHEMA test2;  
CREATE SCHEMA test3;

@kamilwylegala
Copy link
Owner Author

Thanks for docker compose scripts. I think it's worth to include them in repository too.

@kamilwylegala
Copy link
Owner Author

Docker compose setup works like charm 😊

I only get these failures:

There were 3 failures:

1) ShellTest::testCreateFileNoPermissions
Failed asserting that true is false.

/var/www/html/lib/Cake/Test/Case/Console/ShellTest.php:683

2) FolderTest::testRecursiveCreateFailure
Failed asserting that true is false.

/var/www/html/lib/Cake/Test/Case/Utility/FolderTest.php:262

3) FolderTest::testReset
Failed asserting that true is false.

/var/www/html/lib/Cake/Test/Case/Utility/FolderTest.php:878

But I think we can proceed with the PR and focus on these tests in the future.

I will also extend readme about tests and commit your setup of docker-compose to repository after merge of your PR.

@kamilwylegala
Copy link
Owner Author

Merged to master. Closing 😊

@tenkoma
Copy link
Contributor

tenkoma commented Feb 5, 2023

#7 (comment)
Updated my comment so that can also test using PostgreSQL or SQLite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants