@Before
  public void setUpProject() throws IOException, VerificationException {
    assumeTrue("Set the M2_HOME environment variable", System.getenv("M2_HOME") != null);
    assumeTrue(
        "Run from Maven or set the project.version system property",
        System.getProperty("project.version") != null);

    File projectDir =
        ResourceExtractor.extractResourcePath(getClass(), "/testing-project", tmp.getRoot(), true);
    testingProject.prepare(projectDir.toPath());

    verifier = new Verifier(projectDir.getAbsolutePath(), true);
    verifier.setForkJvm(true);

    logPath = Paths.get(verifier.getBasedir()).resolve(verifier.getLogFileName());
  }
Пример #2
0
 /**
  * Creates a "failure" message spitting out the Verifier execution log. This methods does not
  * check any assertion, but should be rather call when you already checked and assertion, you know
  * it is failed, and all you want to fail the test with some extra logging.
  *
  * @param verifier
  * @throws IOException
  * @deprecated This method will make huge/confusing output on build execution, and should not be
  *     used.
  */
 @Deprecated
 public void failTest(final Verifier verifier) throws IOException {
   final File logFile = new File(verifier.getLogFileName());
   final String log = FileUtils.fileRead(logFile);
   Assert.fail(log);
 }
Пример #3
0
  /**
   * tests the goal "convert-phar"
   *
   * @throws Exception
   */
  public void testGoal() throws Exception {
    final Verifier verifierDep1 = this.getPhpMavenVerifier("mojos-phar/phar-with-dep1-folders");

    // delete the pom from previous runs
    verifierDep1.deleteArtifact("org.phpmaven.test", "phar-with-dep1-folders", "0.0.1", "pom");
    verifierDep1.deleteArtifact("org.phpmaven.test", "phar-with-dep1-folders", "0.0.1", "phar");

    // execute testing
    verifierDep1.executeGoal("package");

    // verify no error was thrown
    verifierDep1.verifyErrorFreeLog();

    // reset the streams
    verifierDep1.resetStreams();

    final File phar =
        new File(new File(verifierDep1.getBasedir()), "target/phar-with-dep1-folders-0.0.1.phar");
    assertTrue(phar.exists());

    verifierDep1.setAutoclean(false);

    // to zip
    verifierDep1.addCliOption("-Dfrom=" + phar.getAbsolutePath());
    verifierDep1.addCliOption(
        "-Dto=" + phar.getAbsolutePath().substring(0, phar.getAbsolutePath().length() - 4) + "zip");

    verifierDep1.executeGoal("org.phpmaven:maven-php-plugin:convert-phar");

    // verify no error was thrown
    verifierDep1.verifyErrorFreeLog();

    // reset the streams
    verifierDep1.resetStreams();

    verifierDep1.assertFilePresent("target/phar-with-dep1-folders-0.0.1.zip");

    // to jar
    verifierDep1.getCliOptions().clear();
    verifierDep1.addCliOption(
        "-Dfrom="
            + phar.getAbsolutePath().substring(0, phar.getAbsolutePath().length() - 4)
            + "zip");
    verifierDep1.addCliOption(
        "-Dto=" + phar.getAbsolutePath().substring(0, phar.getAbsolutePath().length() - 4) + "jar");

    verifierDep1.executeGoal("org.phpmaven:maven-php-plugin:convert-phar");

    // verify no error was thrown
    verifierDep1.verifyErrorFreeLog();

    // reset the streams
    verifierDep1.resetStreams();

    verifierDep1.assertFilePresent("target/phar-with-dep1-folders-0.0.1.jar");

    // to phar
    verifierDep1.getCliOptions().clear();
    verifierDep1.addCliOption(
        "-Dfrom="
            + phar.getAbsolutePath().substring(0, phar.getAbsolutePath().length() - 4)
            + "jar");
    verifierDep1.addCliOption(
        "-Dto="
            + phar.getAbsolutePath().substring(0, phar.getAbsolutePath().length() - 4)
            + "2.phar");

    verifierDep1.executeGoal("org.phpmaven:maven-php-plugin:convert-phar");

    // verify no error was thrown
    verifierDep1.verifyErrorFreeLog();

    // reset the streams
    verifierDep1.resetStreams();

    verifierDep1.assertFilePresent("target/phar-with-dep1-folders-0.0.1.2.phar");

    verifierDep1.getCliOptions().clear();
    verifierDep1.addCliOption("-Dphar=target/phar-with-dep1-folders-0.0.1.2.phar");
    verifierDep1.executeGoal("org.phpmaven:maven-php-plugin:list-phar-files");
    @SuppressWarnings("unchecked")
    final List<String> lines =
        verifierDep1.loadFile(verifierDep1.getBasedir(), verifierDep1.getLogFileName(), false);
    boolean found1 = false;
    boolean found2 = false;
    for (final String line : lines) {
      if (line.startsWith(
          "[INFO] " + File.separatorChar + "folderA" + File.separatorChar + "MyClassA.php")) {
        found1 = true;
      }
      if (line.startsWith(
          "[INFO] " + File.separatorChar + "folderB" + File.separatorChar + "MyClassB.php")) {
        found2 = true;
      }
    }

    // verify no error was thrown
    verifierDep1.verifyErrorFreeLog();

    // reset the streams
    verifierDep1.resetStreams();

    assertTrue(found1);
    assertTrue(found2);
  }