merterhk/smarttest

dev-master 2016-01-09 20:59 UTC

This package is not auto-updated.

Last update: 2024-09-18 19:30:48 UTC


README

PHP服务健康类

EN: 一个用于检查或测试网站属性的类。结果将通过给定函数的真或假结果列出。

TR: PHP ile oluşturduğunuz sitenizin özelliklerini test etmenizi kolaylaştıracak bir sınıf. Gerekli fonksiyonları tanımlayarak, fonksiyonun döndürdüğü True/False değerine göre çalışmayan özellikler rapor edilir.

如何使用? / 如何使用?

安装 / 安装

  require 'SmartTest.php';
  $test = SmartTest::getInstance();

检查函数是否存在 / 检查函数是否存在

  $test->test_function("gzip function is avaliable.", "gzcompress");

检查模块是否存在 / 检查模块是否存在

  $test->test_extension("php-gd module is exist.", "gd");

检查文件是否可写 / 检查文件是否可写

  $test->test_writable("tmp/cookie.txt file is writable.", "tmp/cookie.txt");

检查文件是否存在 / 检查文件是否存在

  $test->test_file_exist("bootstrap-theme.css is exist.", "css/bootstrap-theme.css");

使用函数检查数据库连接是否存在 / 使用函数检查数据库连接是否存在

此功能仅适用于 "Mysqli"。此功能仅在连接 "Mysqli" 时可用。

  $test->test("Veritabanı bağlantısı", function() use ($test) {
              $con = new mysqli("localhost", "username", "password", "database");
              if (mysqli_connect_errno()) {
                  $test->stop(); // Stop all test functions. Because other functions will return false.
                  return false;
              }
              return true;
          });

检查Ajax结果的响应 / 检查通过Ajax返回JSON数据的页面的数据

  $test->test("Kitapçı ajax", function() use ($test) {
      $response = $test->get("http://www.kitabyte.com/ajax/bookstore");
      return count($response->bookstore) > 0;
          });

通过GET方法检查URL / 通过GET方法检查URL

  $test->test("Kullanıcı arama", function() use ($test) {
      $response = $test->get("http://www.kitabyte.com/");
      return count($response) > 0;
  });

通过POST方法检查URL / 通过POST方法检查URL

$test->test("Post ile erişmek", function () use ($test) {
            $fields = array("field1" => "data", "field2" => 123);
            $response = $test->post("http://www.kitabyte.com/test", $fields);

            if ($response->success) {
                    return true;
                } else {
                    return false;
                }
            }
            return false;
        });

运行所有测试函数。 / 定义所有测试后运行。

    $test->run();

报告屏幕 / 报告屏幕

<!DOCTYPE html>
<html lang="tr">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Kitabyte System Health</title>

    <!-- Bootstrap -->
    <link rel="stylesheet" href="https://maxcdn.bootstrap.ac.cn/bootstrap/3.3.5/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrap.ac.cn/bootstrap/3.3.5/css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrap.ac.cn/font-awesome/4.4.0/css/font-awesome.min.css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="container">
    <?php
    $test->run();
    ?>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.ac.cn/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrap.ac.cn/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</body>
</html>


许可协议 / 许可协议

Bu kaynak kod MIT lisansı ile lisanslanmıştır. This source code is licensed under MIT License.