Wednesday, 31 July 2024

Can not start mysql docker container in my mac machine

Docker compose file


version: '3'
services:
  mysql:
    container_name: docker_mysql_1
    ports:
      - 3306:3306/tcp
    privileged: true
    restart: on-failure
    environment:
      MYSQL_ROOT_PASSWORD: revenuewire
    command:
      - --innodb_file_per_table=0
      - --innodb_checksum_algorithm=INNODB
      - --binlog_checksum=NONE
      - --sql_mode=NO_ENGINE_SUBSTITUTION
      - --slow-query-log=1
      - --slow-query-log-file=/var/log/mysql/my-slow.log
      - --long_query_time=1
      - --log-queries-not-using-indexes
    image: mysql:8.0
    volumes:
      - mysql:/var/lib/mysql
    network_mode: bridge
volumes:
  mysql:

command to run

docker-compose up -d

Error


2024-07-31T12:03:25.087089Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.39) initializing of server in progress as process 80
2024-07-31T12:03:25.089461Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2024-07-31T12:03:25.089468Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
2024-07-31T12:03:25.089537Z 0 [ERROR] [MY-010119] [Server] Aborting
2024-07-31T12:03:25.089947Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.39)  MySQL Community Server - GPL.

Try to access mysql volume using Docker Desktop Dashboard

Solved

Look like it is mac VM problem. After do the following, it works. Just do not know why

  1. use docker desktop dashboard to delete all mysql images.
  2. delete volume docker_mysql
  3. stop and delete all containers
  4. shut down mac
  5. start mac
  6. docker-compose up -d

Thursday, 18 July 2024

PHPUnit 11

Install

composer require --dev phpunit/phpunit ^11

Solve some issues

After upgrade to PHPUnit 11 for 9, got some issues. Here are how I solved them

Metadata in doc-comments is deprecated and will no longer be supported in PHPUnit 12. Update your test code to use attributes instead.

//old codes
/**
 * Test Migrate profile from vault id
 * @depends testCreateProfile
 */
 public function testMigrateProfileFromVaultId($result)
 
 //new code to fix the problem
 /**
  * Test Migrate profile from vault id
  */
  #[Depends('testCreateProfile')]
  public function testMigrateProfileFromVaultId($result)

ArgumentCountError: Too few arguments to function AuthorizenetTest::testProcessRefund(), 0 passed in /var/www/vendor/phpunit/phpunit/src/Framework/TestCase.php

After use attribute #[Depends('testCreateProfile')], got this error.

//to fix it. add this line in the begin of test class
use PHPUnit\Framework\Attributes\Depends;

Show deprecated details

Need this atribute in phpunit config

displayDetailsOnTestsThatTriggerDeprecations="true"
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnPhpunitDeprecations="true"
bootstrap="./src/bootstrap.php" colors="true" stopOnFailure="true" 
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.2/phpunit.xsd" 
cacheDirectory=".phpunit.cache">

......

</phpunit>
 --display-phpunit-deprecations 

Code Coverage

<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" displayDetailsOnTestsThatTriggerDeprecations="true"
         displayDetailsOnTestsThatTriggerWarnings="true"
         bootstrap="./bootstrap.php" colors="true" stopOnFailure="true"
         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.2/phpunit.xsd" cacheDirectory=".phpunit.cache">
    <coverage>
        <report>
            <clover outputFile="ut_build/logs/clover.xml"/>
            <html outputDirectory="ut_build/logs/clover.html"/>
            <text outputFile="php://stdout" showUncoveredFiles="true" showOnlySummary="true"/>
        </report>
    </coverage>
    <source>
        <include>
            <directory suffix=".php">./src</directory>
        </include>
        <exclude>
            <file>./src/bootstrap.php</file>
            <directory suffix=".php">./src/Scripts</directory>
        </exclude>
    </source>
    <testsuites>
        <testsuite name="rest">
            <directory>./tests</directory>
        </testsuite>
    </testsuites>
    <logging/>
</phpunit>

coverage and source elements are for code coverage

//in xdebug.ini
xdebug.mode=coverage