<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Mehdi Meshkatian</title>
    <description>The latest articles on Forem by Mehdi Meshkatian (@mmeshkatian).</description>
    <link>https://forem.com/mmeshkatian</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1092664%2F3a00b590-2e1b-4bf9-80e0-6e576ec19474.png</url>
      <title>Forem: Mehdi Meshkatian</title>
      <link>https://forem.com/mmeshkatian</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/mmeshkatian"/>
    <language>en</language>
    <item>
      <title>Add coverage rate to a php app gitlab-ci</title>
      <dc:creator>Mehdi Meshkatian</dc:creator>
      <pubDate>Wed, 31 May 2023 00:08:05 +0000</pubDate>
      <link>https://forem.com/mmeshkatian/add-coverage-rate-to-a-laravel-app-gitlab-ci-4cg7</link>
      <guid>https://forem.com/mmeshkatian/add-coverage-rate-to-a-laravel-app-gitlab-ci-4cg7</guid>
      <description>&lt;p&gt;First of all lets make some changes to out dockerfile and add this section into it :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;RUN LC_ALL=C.UTF-8 apt-add-repository ppa:ondrej/php -y

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now we can install php extensions easy pizzy !!&lt;/p&gt;

&lt;p&gt;so we add the build section in out gitlab-ci.yml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;build:
  stage: Build
  image: docker:20.10.16
  services:
    - docker:dind
  script:
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker build --pull -t $IMAGE_TAG .
    - docker push $IMAGE_TAG
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now we have our image ready just after this section finished&lt;/p&gt;

&lt;p&gt;after that we may create a test section and install xdebug that its required just in this stage :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;code-coverage:
  stage: Test
  image: $IMAGE_TAG
  script:
    - apt-get update
    - apt-get install -y php8.2-xdebug
    - export XDEBUG_MODE=coverage

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;we should avoid install xdebug directly in dockerfile because its reduce the performance !&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--E_wu6x8P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1lnijqjcl289wwxyy6p1.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--E_wu6x8P--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1lnijqjcl289wwxyy6p1.gif" alt="Image description" width="384" height="256"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Just one more section and then our coverage indicator is ready&lt;/p&gt;

&lt;p&gt;add this line so it will run the code coverage test and extract out the coverage percent to gitlab and also make a copy of tests results so we can check them in merge requests&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;code-coverage:
  stage: Test
  image: $IMAGE_TAG
  script:
    - apt-get update
    - apt-get install -y php8.2-xdebug
    - export XDEBUG_MODE=coverage
    - ./vendor/bin/phpunit --do-not-cache-result --log-junit phpunit-report.xml --coverage-cobertura phpunit-coverage.xml --coverage-text --colors=never
  artifacts:
    when: always
    reports:
      junit: phpunit-report.xml
      coverage_report:
        coverage_format: cobertura
        path: phpunit-coverage.xml
  coverage: '/^\s*Lines:\s*\d+.\d+\%/'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now lets create a merge request and we what happens after pipelines passed : &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_wmA09j0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/viwu1thqzwlvvb4uo1st.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_wmA09j0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/viwu1thqzwlvvb4uo1st.png" alt="Image description" width="790" height="168"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7xDajbfu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mdejmjp4jntomcn9q73y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7xDajbfu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mdejmjp4jntomcn9q73y.png" alt="Image description" width="800" height="63"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vxSee7dO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aohzgt5tcgizs2wzzmmi.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vxSee7dO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aohzgt5tcgizs2wzzmmi.gif" alt="Image description" width="498" height="278"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>devops</category>
      <category>php</category>
      <category>laravel</category>
      <category>gitlab</category>
    </item>
  </channel>
</rss>
